
6 Jun
2005
6 Jun
'05
3:04 p.m.
On Mon, Jun 06, 2005 at 03:58:41PM +0200, Lorenzo Bettini wrote:
However, it is not clear to me how to use weak_ptr in this context...
can some one provide some clue, please?
Well, for this context: class C; typedef boost::shared_ptr<C> CP; typedef boost::weak_ptr<C> WP; class C { private: string s; WP wp; public: C(const string &ss, CP c = CP()) : s(ss), wp(c) {} void set(CP c) { wp = c; } ~C() { cout << "destroying C" << endl; } }; Then main() would be unchanged. That might not work for anything less trivial than your example, since you'd need to ensure the shared_ptrs that own the objects are still around when you use the weak_ptrs. jon