template<typename T, typename P = void>
class SmartPointer< T, P >
Smart pointers avoid destruction of an object in use. They can be used just like a pointer (i.e. using the
-> operators and through casting) but make sure that the object pointed to is not deleted in the course of use of the pointer by signaling the pointee its use.
Objects pointed to, i.e. the class T, should inherit Subscriptor or must implement the same functionality. Null pointers are an exception from this rule and are allowed, too.
The second template argument P only serves a single purpose: if a constructor without a debug string is used, then the name of P is used as the debug string.
SmartPointer does NOT implement any memory handling! Especially, deleting a SmartPointer does not delete the object. Writing
is a sure way to program a memory leak! The secure version is
T* p = new T;
Note that a smart pointer can handle
constness of an object, i.e. a
SmartPointer<const ABC> really behaves as if it were a pointer to a constant object (disallowing write access when dereferenced), while
SmartPointer<ABC> is a mutable pointer.
- Guido Kanschat, Wolfgang Bangerth, 1998 - 2009
Definition at line 63 of file smartpointer.h.
template<typename T, typename P >
Swap pointers between this object and the pointer given. As this releases the object pointed to presently, we reduce its subscription count by one, and increase it at the object which we will point to in the future.
Note that we indeed need a reference of a pointer, as we want to change the pointer variable which we are given.
Definition at line 391 of file smartpointer.h.