A member of my class is a boost::scoped_ptr which is set to (T*)0 when the object is created. The class has an init() method that actually initializes the smart pointer with a new object.
However, if an exception is thrown before that smart pointer has a valid reference, it very un-smartly tries to delete null (release) or it asserts (debug).
How do I get it to ignore null pointers upon destruction without modifying the original source code; and, if that isn’t possible, is there a more suitable alternate smart pointer class to use instead?
boost::scoped_ptr actually ignores null pointers in its destructor. boost::scoped_ptr uses boost::checked_delete() for deletion. boost::checked_delete() uses plain
deletein order to delete (boost::checked_delete() also checks so that T is not incomplete).And you are allowed to delete null pointers with delete (unlike
free()). Are you sure that the error is really in boost::scoped_ptr ?