enable_shared_from_this and constructor
Hello,
why is not possible to call this:
-- cut here --
#include
Petr Ferschmann wrote:
Hello,
why is not possible to call this: [...] class Trida : public boost::enable_shared_from_this<Trida> { public: Trida() { trida = this->shared_from_this(); }; }; [...] It throws in constructor of shared_count(weak_count const & r).
I think the problem is that there is no one shared_ptr instance that owns object tr yet when calling constructor.
You are right. To call shared_from_this, you need first to ensure that at least one shared_ptr points to the object, as stated in the Requires clause.
May be it is BUG (and I don't know how to handle that). Can be at least note in documentation?
See http://www.boost.org/libs/smart_ptr/sp_techniques.html#in_constructor
participants (2)
-
Peter Dimov
-
Petr Ferschmann