
14 May
2003
14 May
'03
1:26 p.m.
ostware wrote:
class T : public enable_shared_from_this { public: T() {} ~T() { shared_ptr<T> ptr = shared_from_this(); // trouble: exception, can't get a shared_ptr
What are you trying to achieve with this? ~T has already started; the object is on its way to A Better Place. Even if you could get a shared_ptr to it, you can't stop the object's destruction. The shared_ptr would point to a destroyed T once ~T finishes. If you want to have a shared_ptr instance to 'this' that is valid only for the duration of ~T, you can use a null deleter, as described in http://www.boost.org/libs/smart_ptr/sp_techniques.html#static HTH
} };