29 Sep
2002
29 Sep
'02
9:11 p.m.
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. } }