fork(1) download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. using namespace std;
  5. struct B;
  6. struct A
  7. {
  8.  
  9. shared_ptr<B> b;
  10. ~A()
  11. {
  12. std::cout << __PRETTY_FUNCTION__ << '\n';
  13. }
  14. };
  15.  
  16. struct B
  17. {
  18. weak_ptr<A> a;
  19. ~B()
  20. {
  21. std::cout << __PRETTY_FUNCTION__ << '\n';
  22. }
  23.  
  24. };
  25.  
  26. int main()
  27. {
  28. shared_ptr<A> x(new A);
  29. x->b.reset(new B);
  30. x->b->a = x;
  31. x->b->a.lock();
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
A::~A()
B::~B()