Boost logo

Boost Users :

From: Daniel P Furlani (Daniel_P_Furlani_at_[hidden])
Date: 2007-12-05 16:06:19


Is there a way to call shared_from_this() from a constructor?

It seems like a bad idea. Since the object is still being created, it
would be difficult for anything to have a shared_ptr to it. And that
violates a documented precondition of shared_from_this(): "There must
exist at least one shared_ptr instance p that owns t."

If it's not possible or just a bad idea, how about a note in the
documentation at:
    http://www.boost.org/libs/smart_ptr/enable_shared_from_this.html
to say something like: "Calling shared_from_this from a constructor will
not work, since there is no shared_pointer which owns the object."?

-dan



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