[prev in list] [next in list] [prev in thread] [next in thread] 

List:       boost-users
Subject:    Re: [Boost-users] [shared_ptr] Problem refeering back to a parent
From:       Rupert Swarbrick <rupert.swarbrick () lineone ! net>
Date:       2006-04-30 11:03:20
Message-ID: e325i1$3ld$1 () sea ! gmane ! org
[Download RAW message or body]

Sebastian Redl wrote:
> Eoin wrote:
> 
>> But I get a boost::bad_weak_ptr error. Now if I use regular pointers
>> instead of weak_ptr's I can get stuff working except that when I use
>> "bar_(this)" in the initialization list for foo MSVC 7.1 gives me a
>> warning, which I don't like. Is there a more appropriate method I should
>> be using to accomplish this.
>>  
>>
> Just use a regular pointer. As the bar object is a subobject of foo, it 
> is guaranteed to be destructed first, meaning that the pointer can never 
> be invalid in the lifetime of bar.
> 
> Sebastian Redl

May I second that.

There's an example somewhere on the web of using another shared_ptr but
with a null destructor, which I followed. The following day, I realised
it was a complete waste of time - you only need one shared ptr after all
to get rid of all the horrible double free errors! :)

Rupert


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic