#include #include using std::cout; using std::endl; using std::weak_ptr; using std::shared_ptr; struct Son; struct Daughter; struct Mother{ ~Mother(){cout << "Mother gone" << endl;} void setSon(const shared_ptr s ){ mySon=s; } void setDaughter(const shared_ptr d ){ myDaughter=d; } shared_ptr mySon; weak_ptr myDaughter; }; struct Son{ Son(shared_ptr m):myMother(m){} ~Son(){cout << "Son gone" << endl;} shared_ptr myMother; }; struct Daughter{ Daughter(shared_ptr m):myMother(m){} ~Daughter(){cout << "Daughter gone" << endl;} shared_ptr myMother; }; int main(){ cout << endl; { shared_ptr mother= shared_ptr( new Mother); shared_ptr son= shared_ptr( new Son(mother) ); shared_ptr daugher= shared_ptr( new Daughter(mother) ); mother->setSon(son); mother->setDaughter(daugher); } cout << endl; }