fork download
  1. #include <iostream>
  2.  
  3. struct X
  4. {
  5. X(int i)
  6. {
  7. x = i;
  8. std::cerr << "X ctor, x = " << x << std::endl;
  9. }
  10. int x;
  11. };
  12.  
  13. void f()
  14. {
  15. static X ix(0);
  16. std::cerr << "f(), ix.x = " << ix.x << std::endl;
  17.  
  18. ++ix.x;
  19. if (ix.x > 5)
  20. {
  21. static X iy(ix.x);
  22. static X iz(ix); // copy constructor
  23. }
  24. }
  25.  
  26. int main()
  27. {
  28. for ( int i = 0; i < 10; ++i) f();
  29. return 0;
  30. }
Success #stdin #stdout #stderr 0s 3092KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
X ctor, x = 0
f(), ix.x = 0
f(), ix.x = 1
f(), ix.x = 2
f(), ix.x = 3
f(), ix.x = 4
f(), ix.x = 5
X ctor, x = 6
f(), ix.x = 6
f(), ix.x = 7
f(), ix.x = 8
f(), ix.x = 9