Boost logo

Boost :

From: Lorenzo Bettini (bettini_at_[hidden])
Date: 2005-06-06 10:34:13


Jonathan Wakely wrote:
> 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.

indeed, it only works for that simple main: the main problem I had is
just "ensure the shared_ptrs that own the objects are still
around when you use the weak_ptrs.".

Moreover, I had to deal with mutual dependences, and this makes the
whole thing worse...


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk