Richard Damon wrote:
One comment is that:
Class A { }; // No virtual destructor
Class B : public A { }
shared_ptr<A>(new B)
Should cause UB as the shared pointer will will eventually call delete on its parameter, and since A has no virtual destructor and is NOT the type the object was created with, you get UB.
It basically boils down to the equivalent to this
A* ptr = new B; delete ptr;
which is a no-no.
A NEEDS to have a virtual destructor to use it the way you are. Richard
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi Richard, actually it's ok with shared_ptr. Here is a short snip from the docs: ... This constructor has been changed to a template in order to remember the actual pointer type passed. The destructor will call delete with the same pointer, complete with its original type, even when T does not have a virtual destructor, or is void. ...