Boost logo

Boost Users :

From: dick.bridges_at_[hidden]
Date: 2002-09-29 16:11:13


I run into situations where it's useful for an object to have a
'backpointer' to the object instance that created it (example below). Is
there a pattern/idiom for doing this using shared_ptr? Or maybe I need to
re-think the idea of the backpointer in the first place?

class Bar;

class Foo
{
public:
      Foo(Bar* b) : p(b){}

private:
      Foo() : p(0){}

      shared_ptr<Bar> p;
}

class Bar
{
      void doit()
      {
            new Foo(???); // <<< new Foo(this) obviously won't work.
      }
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net