22 Nov
2006
22 Nov
'06
6:13 p.m.
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();