fork download
  1. #include <iostream>
  2.  
  3. struct Counter{
  4. Counter():v(++i){ std::cout << "ctor:" << v << std::endl; }
  5. ~Counter(){ std::cout << "dtor:" << v << std::endl; }
  6. Counter f() const { return Counter(); }
  7. const int v;
  8. static int i;
  9. };
  10. int Counter::i=0;
  11.  
  12. int main(void){
  13. Counter c;
  14. c.f().f().f().f().f();
  15. return 0;
  16. }
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
ctor:1
ctor:2
ctor:3
ctor:4
ctor:5
ctor:6
dtor:6
dtor:5
dtor:4
dtor:3
dtor:2
dtor:1