Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. struct A
  4. {
  5. A() { std::cout << "ctor " << this << std::endl; }
  6. ~A() { std::cout << "dtor " << this << std::endl; }
  7. void f() { std::cout << "f " << this << std::endl; }
  8. };
  9.  
  10. struct S
  11. {
  12. inline static A a; // C++17 inline variable, thus also a definition
  13. };
  14.  
  15. #include "header.h"
  16.  
  17. int main()
  18. {
  19. S::a.f();
  20. }
  21.  
  22. #include "header.h"
  23.  
  24. #include "header.h"
  25.  
  26. #include "header.h"
  27.  
  28. ctor 010D4020
  29. ctor 010D4020
  30. ctor 010D4020
  31. ctor 010D4020
  32. f 010D4020
  33. dtor 010D4020
  34. dtor 010D4020
  35. dtor 010D4020
  36. dtor 010D4020
  37.  
  38. ctor 010D4020
  39. f 010D4020
  40. dtor 010D4020
  41.  
  42. struct A
  43. {
  44. A() { std::cout << "ctor "; }
  45. ~A() { std::cout << "dtor "; }
  46. };
  47.  
  48. A a; // in one of the TU's
  49.  
  50. extern A a; // in all other TU's
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement