fork download
  1. #include <iostream>
  2.  
  3. struct A
  4. {
  5. A() { std::cout << this << ":\tA::A()\n"; }
  6. ~A() { std::cout << this << ":\tA::~A()\n"; }
  7. };
  8.  
  9. struct C
  10. {
  11. C() { std::cout << this << ":\tC::C()\n"; }
  12. C(const C&) { std::cout << this << ":\tC::C(const C&)\n"; }
  13. ~C() { std::cout << this << ":\tC::~C()\n"; }
  14. };
  15.  
  16. struct B
  17. {
  18. public:
  19. operator A() const { return A(); }
  20. operator C() const { return C(); }
  21. };
  22.  
  23. void f(A q) { std::cout << "In f, q's address is " << &q << '\n'; }
  24. void g(C q) { std::cout << "In g, q's address is " << &q << '\n'; }
  25.  
  26. int main()
  27. {
  28. B d1;
  29. f(d1);
  30. g(d1);
  31. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
0xbf88734f:	A::A()
In f, q's address is 0xbf88734f
0xbf88734f:	A::~A()
0xbf88734f:	C::C()
In g, q's address is 0xbf88734f
0xbf88734f:	C::~C()