fork download
  1. #include <iostream>
  2.  
  3. #define O(x) std::cout << (x) << std::endl;
  4.  
  5. struct foo
  6. {
  7. foo() { O("foo"); }
  8. ~foo() { O("~foo"); }
  9. };
  10.  
  11. struct bar
  12. {
  13. bar() { O("bar"); }
  14. ~bar() { O("~bar"); }
  15. };
  16.  
  17. foo& global_foo()
  18. {
  19. static foo result;
  20. return result;
  21. }
  22.  
  23. bar& global_bar()
  24. {
  25. static bar result;
  26. return result;
  27. }
  28.  
  29. int main()
  30. {
  31. O("main");
  32.  
  33. global_foo();
  34. global_bar();
  35.  
  36. O("~main");
  37. }
Success #stdin #stdout 0s 2828KB
stdin
Standard input is empty
stdout
main
foo
bar
~main
~bar
~foo