I have not tested this, but you should be able to use a custom deallocator object to keep a shared_ptr to the parent around as long as the child is still needed. Something along these lines: template class Guard { private: boost::shared_ptr *parent; public: explicit Guard(const boost::shared_ptr a_parent) { // Save one shared_ptr to parent (in this guard object and all it's copies) // This keeps the parent alive. Parent = new boost::shared_ptr(a_parent); } void operator()(Child *child) { // The smart pointer says to "delete" the child, so delete the shared_ptr // to parent.As far as we are concerned, the parent can die now.
Delete parent; } }; // ... boost::shared_ptr par; boost::shared_ptr ch(&par->b, Guard(par)).
D'oh! Found it right in shared_ptr documentation. It's called aliasing (see section III of shared_ptr improvements for C++0x).
I just needed to use a different constructor (or a corresponding reset function overload): template shared_ptr( shared_ptr const & r, T * p ); Which works like this (you need to construct shared_ptr to parent first): #include #include struct A { A() : i_(13) {} int i_; }; struct B { A a_; ~B() { std::cout a; { boost::shared_ptr b(new B); a = boost::shared_ptr(b, &b->a_); std::cout i.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.