Boost logo

Boost :

From: Thomas Witt (witt_at_[hidden])
Date: 2002-09-09 15:27:01


On Monday 09 September 2002 21:58, Peter Dimov wrote:
> Yes. I need to add this to the documentation one day. This is the "can an
> object create weak pointers to itself in its constructor" question, and the
> answer is "no, make the constructor private, provide a factory method that
> creates shared_ptr<Object> and then creates the weak pointers." You might
> even be able to avoid the counted_base.

IIUC creating shared_ptr's is dangerous as well. Lets assume A takes a

  a_.reset(new A(shared_from_this(this));

If A's ctor throws the dtor of B will be called before its ctor has finished.
It's dangerous business to handle not-fully-constructed objects.


Dipl.-Ing. Thomas Witt
Institut fuer Verkehrswesen, Eisenbahnbau und -betrieb, Universitaet Hannover
voice: +49(0) 511 762 - 4273, fax: +49(0) 511 762-3001

Boost list run by bdawes at, gregod at, cpdaniel at, john at