fork download
  1. #include <iostream>
  2.  
  3. struct X
  4. {
  5. X() : i_(0) { std::cout << "X(" << this << ")\n"; }
  6. X(int i) : i_(i) { std::cout << "X(" << this << ", i " << i << ")\n"; }
  7. X(const X& rhs) : i_(rhs.i_) { std::cout << "X(" << this << ", const X& " << &rhs << ")\n"; }
  8. ~X() { std::cout << "~X(" << this << ")\n"; }
  9. X func() { std::cout << "X::func(this " << this << ")\n"; X x(2); return x; }
  10. int i_;
  11. };
  12.  
  13. int main()
  14. {
  15. X x1;
  16. X x2 = x1.func();
  17. std::cout << "x1 " << &x1 << ", x2 " << &x2 << '\n';
  18. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
X(0xbfd346e8)
X::func(this 0xbfd346e8)
X(0xbfd346ec, i 2)
x1 0xbfd346e8, x2 0xbfd346ec
~X(0xbfd346ec)
~X(0xbfd346e8)