Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-04-28 11:55:30


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


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