From: Phil Nash (phil.nash.lists_at_[hidden])
Date: 2002-06-26 08:42:33
> Peter Dimov wrote:
> > Yes, I see the problem. In the current implementation, you have to
> > owning pointer to the object first, before any weak pointers, since
> > counted_base interprets use_count = 0, weak_count != 0 as an indication
> > 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.
Yes, and that is why I am having the problem I am having. The definition you
give is sound, it's the fact that the object is not owned when I when I want
to take weak pointers to it that is my problem.
> > So it seems that you can't create weak_ptr's in the object constructor.
> > 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.
Yes, I had been using just this method as a work-around until now. But it
*does* seem like a work-around to me, rather than a proper solution - and in
some cases does complicate the code in ways that seem unnecessary.
However, I believe I have solved my problem now and you can see what I am
doing in my latest reply to Peter.
It's not a 100% perfect solution, but it's an attempt to solve the issue at
source, rather than working around it.
Of course, you may disagree and suggest that the factory method is a
solution rather than a work around, and my concept is misguided - in which
case I am open to persuasion :-)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk