class template
<memory>
std::auto_ptr
template <class X> class auto_ptr;
Automatic Pointer [deprecated]
Note: This class template is deprecated as of C++11. unique_ptr is a new facility with a similar functionality, but with improved security (no fake copy assignments), added features (deleters) and support for arrays. See unique_ptr for additional information.
This class template provides a limited garbage collection facility for pointers, by allowing pointers to have the elements they point to automatically destroyed when the auto_ptr object is itself destroyed.
auto_ptr objects have the peculiarity of taking ownership of the pointers assigned to them: An auto_ptr object that has ownership over one element is in charge of destroying the element it points to and to deallocate the memory allocated to it when itself is destroyed. The destructor does this by calling operator delete automatically.
Therefore, no two auto_ptr objects should own the same element, since both would try to destruct them at some point. When an assignment operation takes place between two auto_ptr objects, ownership is transferred, which means that the object losing ownership is set to no longer point to the element (it is set to the null pointer).
Template parameters
- X
- The type of the managed object, aliased as member type element_type.
Member types
The following alias is a member type of auto_ptr.
member type | definition | notes |
element_type | class template parameter (X) | The type of the managed object |
Member functions
- (constructor)
- Construct auto_ptr object (public member function)
- (destructor)
- Destroy auto_ptr (public member function)
- get
- Get pointer (public member function)
- operator*
- Dereference object (public member function)
- operator->
- Dereference object member (public member function)
- operator=
- Release and copy auto_ptr (public member function)
- release
- Release pointer (public member function)
- reset
- Deallocate object pointed and set new value (public member function)
- (conversion operators)
- Conversion operators (public member function)