#include <iostream> struct X { X(int i) { x = i; std::cerr << "X ctor, x = " << x << std::endl; } int x; }; void f() { static X ix(0); std::cerr << "f(), ix.x = " << ix.x << std::endl; ++ix.x; if (ix.x > 5) { static X iy(ix.x); static X iz(ix); // copy constructor } } int main() { for ( int i = 0; i < 10; ++i) f(); return 0; }
Standard input is empty
Standard output is empty
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