fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct A {
  5. A() {cout<<"A:"<<this<<endl;}
  6. ~A() {cout<<"~A:"<<this<<endl;}
  7. void f() const {cout<<x<<endl;}
  8. int x = 5;
  9. };
  10.  
  11. struct B {
  12. B(const A& a) : a(a) {
  13. cout<<"B"<<endl;
  14. }
  15. void g() {
  16. a.f();
  17. }
  18. const A a;
  19. };
  20.  
  21. int main() {
  22. // your code goes here
  23. B*b;
  24. {
  25. A a;
  26. cout<<"before f"<<endl;
  27. b = new B(move(a));
  28. cout<<"after f"<<endl;
  29. a.f();
  30. }
  31. b->g();
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5548KB
stdin
Standard input is empty
stdout
A:0x7ffdf34fe734
before f
B
after f
5
~A:0x7ffdf34fe734
5