classPiiSmartPtr
#include <PiiSmartPtr.h>
A utility class that works as a simple alternative to std::auto_ptr.
Description
PiiSmartPtr is used as a stack-allocated object that deletes its pointer upon destruction. It doesn't provide copy semantics. Contrary to std::auto_ptr, PiiSmartPtr also works for arrays.
The main use of PiiSmartPtr is in guarding heap-allocated pointers in functions that may throw exceptions. Use like this:
PiiSmartPtr<int[]> ptr(new int[5]); // arrays PiiSmartPtr<int> ptr(new int); // any other pointers
Constructors and destructor
|
( )
|
|
|
(
Create a new PiiSmartPtr that wraps the given pointer. |
|
|
( )
Delete the wrapped pointer. |
Public member functions
|
( )
This allows one to use PiiSmartPtr<T> as a T*. |
|
|
T *
|
( )
Masquerades the class as a pointer. |
|
(
|
|
|
T *
|
( )
Release the ownership of the pointer. |
Function details
-
PiiSmartPtr
()[inline] -
PiiSmartPtr
(- T * ptr
[inline]Create a new PiiSmartPtr that wraps the given pointer.
Ownership of the pointer is taken.
-
~PiiSmartPtr
()[inline]Delete the wrapped pointer.
-
operator T *
()[inline]This allows one to use PiiSmartPtr<T> as a T*.
-
T * operator->
()[inline]Masquerades the class as a pointer.
-
-
T * release
()[inline]Release the ownership of the pointer.
The pointer is returned.
Add a note
Not a single note added yet. Be the first, add yours.