Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-05-09 18:27:43


Olivier Tournaire wrote:

> if ( typeid(m_rectangle.get()) == typeid(rectangle*) )
> {
> boost::shared_ptr<rectangle> rect(
> (rectangle*)(m_rectangle.get()) );

This is the cause of your immediate problem. You are creating a second
shared_ptr to the same raw pointer. This second shared_ptr has no knowledge
of m_rectangle and will call delete on the raw pointer when it goes out of
scope. Why not just use m_rectangle inside the if? You don't need the cast
or the second shared_ptr.


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