|
Boost Users : |
From: Philipp Henkel (threadpool_at_[hidden])
Date: 2007-01-24 13:48:21
He Ethann,
On 1/23/07, ethann.castell_at_[hidden] <ethann.castell_at_[hidden]> wrote:
>
> class B1 : public B
> {
> public:
> B1(boost::shared_ptr<base_class> pLinked) : B( pLinked){}
> ~B1()
> {
> try{
> boost::shared_ptr<base_class> ptr_This =
> shared_from_this(); // Exception occurs here
Let me explain why this is exception is thrown. As I said before the object
has to be owned by a shared_ptr whenever your are calling shared_from_this().
To trigger the object's destruction (we are in the destructor) somebody
called delete on the object. This can only be the case if the last
shared_ptr released the object (if there isn't another error). Therefore you
are not allowed to call shared_from_this() anymore.
> if (f == 3){
> boost::shared_ptr<B2> ptr_b2( new B2(ptr_me) ) ;
> // create new B2 and pass pointer to me.
> }else{
> // crashes with bad_weak_ptr error on this line.
>
This is the same problem again. The exception is thrown by B1's destructor
(B2 is derived from B1).
Best regards,
Philipp
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