Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2006-11-22 14:23:05


But now that I look at this, I'm wondering:

Will t.lock() succeed if t is in an an "expired" state?

Robert Ramey

Robert Ramey wrote:
> Very good. I'll make this tweak and check it in.
>
> Robert Ramey
>
>
>
>
> Peter Dimov wrote:
>> Mikko Vainio wrote:
>>> Hi,
>>>
>>> I'm trying to serialize an object of class X that has a member
>>> boost::weak_ptr< X >. The weak pointer may as well be empty and the
>>> object is still in valid state - at least in this context. The
>>> serialization code, however, tries to make a shared_ptr out of the
>>> weak_ptr, which throws a bad_weak_ptr when the weak_ptr is empty.
>>> Should the weak_ptr be checked for expired() before trying to make a
>>> shared_ptr of it?
>>
>> The line
>>
>> const boost::shared_ptr<T> sp(t);
>>
>> should be
>>
>> const boost::shared_ptr<T> sp = t.lock();


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