|
Boost Users : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-05-14 08:26:04
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
> }
> };
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