#include <FXPtrHold.h>
In code using exception handling, a major problem is allocating pointers on the stack to objects and then correctly freeing them on exception. The solution is this class which guarantees deletion of new-ed pointers stored inside it.
FXPtrHold<FXString> temp; FXERRHM(temp=new FXString);
Why use this instead of std::auto_ptr
from the STL? Well auto_ptr
has the concept of ownership of the pointed to data and assignments from one to the other zeros the copyee. FXPtrHold behaves much more like a vanilla auto pointer - the sole difference it that it deletes its contents on destruction.
Needless to say, you should zero its contents if you delete them manually. FXDELETE() helps you here. Remember also that if you do make copies, deleting one means setting the rest to zero to prevent a run-time error.
delete ptr
.
Definition at line 62 of file FXPtrHold.h.
Public Member Functions | |
FXPtrHold (type *p=0) throw () | |
~FXPtrHold () | |
operator type * () throw () | |
operator const type * () const throw () | |
type *& | operator-> () throw () |
type *& | operator= (type *p) throw () |
void | free () |