Boost logo

Boost Users :

Subject: Re: [Boost-users] shared_ptr and circular dependency
From: Christopher Pisz (cpisz_at_[hidden])
Date: 2012-03-30 16:14:18


Emil Dotchevski <emildotchevski <at> gmail.com> writes:

>
> On Fri, Mar 30, 2012 at 12:26 PM, Christopher Pisz <cpisz <at>
austin.rr.com> wrote:
> >
> > What are one's options when the code one is working on contains a circular
> > dependency and one is trying to update it to use a shared_ptr vs a raw
pointer?
>
> You could use weak_ptr to break shared_ptr cycles.
>
> Emil Dotchevski
> Reverge Studios, Inc.
> http://www.revergestudios.com/reblog/index.php?n=ReCode
>

>From boost docs:
Q. Can an object create a weak_ptr to itself in its constructor?

A. No. A weak_ptr can only be created from a shared_ptr, and at object
construction time no shared_ptr to the object exists yet.

This is the problem I cannot seem to easily overcome in both the case of the
shared and weak ptr. It seems to work with a raw this pointer, but then I
cannot achieve my goal.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net