Boost logo

Boost Users :

Subject: Re: [Boost-users] [Smart Pointers] enable_shared_from_this::shared_from_this() behaviour query
From: David Blaikie (dblaikie_at_[hidden])
Date: 2011-06-13 01:29:01

> shared_from_this() throws bad_weak_ptr if it's called in a derived
> destructor even if the object is heap allocated, does anyone know if this is
> intended? And if so, why?

What else could it do? if the dtor is running the refcount has reached
zero... and, well, you know, the dtor is running.

If you created a shared_ptr to that object - what would happen when that new
shared_ptr went out of scope? The refcount would reach zero (again) & the
object would be double deleted.

What semantics were you expecting?

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at