auto_ptr


A templatized smart pointer class.

The auto_ptr class is used to automatically manage pointers to dynamically created objects. When an auto_ptr is destroyed, the object it points to is also destroyed. Only one auto_ptr can own an object at a time; copying an auto_ptr will transfer the object pointer and ownership of the object to the destination auto_ptr . Therefore, auto_ptr s can be used safely as return values for functions.

Library

Standards<ToolKit>

Declaration

#include <memory>

template< class T >
class auto_ptr

Interface

Constructor
explicit auto_ptr( T* ptr )
Constructs an auto pointer to manage the object pointed to by ptr (default 0 ).
Constructor
auto_ptr( auto_ptr< T >& other )
Constructs an auto pointer and assumes ownership of the object managed by other .
Destructor
~auto_ptr()
Destroys the auto pointer and the object it manages.
=
auto_ptr< T >& operator=( auto_ptr< T >& other )
Assumes ownership of the object managed by other . If the auto pointer already manages an object, destroys the original object first.
*
T& operator*() const
Returns a reference to the auto pointer's managed object.
->
T* operator->() const
Returns a pointer to the object auto pointer manages.
get
T* get() const
Returns a pointer to the object auto pointer manages.
release
T* release()
Returns a pointer to the auto pointer's managed object and releases ownership.

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.