Boost logo

Boost Users :

Subject: [Boost-users] [Smart Pointers] enable_shared_from_this::shared_from_this() behaviour query
From: eddyaod_at_[hidden]
Date: 2011-06-12 22:03:27


shared_from_this() throws bad_weak_ptr if it's called in a derived
destructor even if the object is heap allocated, does anyone know if this is
intended? And if so, why?

Example:

class DestructorCheck : public std::tr1::enable_shared_from_this
<DestructorCheck>
{
public:
DestructorCheck()
    {
    }
~DestructorCheck()
    {
    shared_from_this();
    }
};

BOOST_AUTO_TEST_CASE(enable_weakTests)
{
BOOST_CHECK_THROW( { DestructorCheck d; } , std::tr1::bad_weak_ptr )
BOOST_CHECK_NO_THROW( { std::tr1::shared_ptr<DestructorCheck> d =
boost::make_shared<DestructorCheck>(); } )
}



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