fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. using namespace std;
  5.  
  6. class second;
  7.  
  8. class first {
  9. unique_ptr<second> p2;
  10. first() {}
  11. public:
  12. static shared_ptr<first> create() {
  13. shared_ptr<first> f{new first};
  14. f->p2 = make_unique<second>(f);
  15. return f;
  16. }
  17. };
  18.  
  19. class second {
  20. shared_ptr<first> p1;
  21. public:
  22. second(shared_ptr<first> arg) : p1(arg) {}
  23. };
  24.  
  25. int main()
  26. {
  27. auto f = first::create();
  28. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
Standard output is empty