Boost logo

Boost :

From: Nicola Musatti (Nicola.Musatti_at_[hidden])
Date: 2002-06-26 03:55:15


Peter Dimov wrote:
[...]
> Yes, I see the problem. In the current implementation, you have to create an
> owning pointer to the object first, before any weak pointers, since
> counted_base interprets use_count = 0, weak_count != 0 as an indication that
> dispose() has already been called.

Pardon my butting in, but I find this very reasonable; in my
understanding a weak pointer to an object that is not owned should be
null by definition.

> So it seems that you can't create weak_ptr's in the object constructor. You
> need a shared_ptr first, and you can't create a temporary shared_ptr to
> 'this' in the constructor since it will call dispose() on block exit.

The solution is to use a factory object that holds a shared pointer to
the main object and supplies the wek pointers.
 
Cheers,
Nicola Musatti


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