Boost logo

Boost Users :

From: Jason Winnebeck (yg-boost-users_at_[hidden])
Date: 2003-07-18 12:47:08


Peter Dimov wrote:
> Multiple inheritance from concrete classes is just problematic, in more ways
> that just enable_shared_from_this not working. :-)

Yes I know that ;). This is the only time I've done it and perhaps I've
made a mistake. I have a class Thread, so objects that are Threads
inherit from Thread and something else sometimes. I probably should
have considered doing something like the Runnable interface from Java,
espically since I modeled my API similarly to Java's Thread class.

What I do with shared_ptr, is that I have to enforce a "base" reference,
so there is a map of threads where the references are stored. This
keeps the Thread instance alive while the Thread is running. Thus when
a Thread starts, its shared_ptr is needed.

> static sptr create() {
> sptr this_( new Base1() );
> register(this_);
> return this_;
> }

I do keep that in mind. I have done that in some places.

> In general, enable_shared_from_this is to be avoided. You only need it in
> some rare cases.

Hmm I thought it would be a good thing to have a lot of the classes
provide a "getPointer" method. Well actually I just realized that is
pretty flat out moronic, because you need a shared_ptr to call the get
function, unless you are given a reference (which does happen in the
listeners as you suggested earlier).

Jason


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