< cpp‎ | memory
Revision as of 08:13, 7 November 2012 by P12 (Talk | contribs)


Template:ddcl list begin <tr class="t-dsc-header">

Defined in header <memory>

<td></td> <td></td> </tr> <tr class="t-dcl ">

<td >
template< class T > class auto_ptr;

<td > (1) </td> <td > (deprecated) </td> </tr> <tr class="t-dcl ">

<td >
template<> class auto_ptr<void>

<td > (2) </td> <td > (deprecated) </td> </tr> Template:ddcl list end

auto_ptr is a smart pointer that manages an object obtained via new and deletes that object when auto_ptr itself is destroyed. It may be used to provide exception safety for dynamically-allocated objects, for passing ownership of dynamically-allocated objects into functions and for returning dynamically-allocated objects from functions.

Copying an auto_ptr copies the pointer and transfers ownership to the destination: both copy construction and copy assignment of auto_ptr modify their right hand arguments, and the "copy" is not equal to the original. Because of these unusual copy semantics, auto_ptr may not be placed in standard containers. std::unique_ptr is preferred for this and other uses.

2) Specialization for type void is provided, it declares the typedef element_type, but no member functions.

An additional class template auto_ptr_ref is referred to throughout the documentation. It is an implementation-defined type that holds a reference to auto_ptr. The implementation is allowed to provide the template with a different name or implement the functions returning it or accepting it as parameter in other ways.


Member types

Member type Definition
element_type T

Member functions

Template:cpp/memory/auto ptr/dcl list auto ptrTemplate:cpp/memory/auto ptr/dcl list ~auto ptrTemplate:cpp/memory/auto ptr/dcl list operator=Template:cpp/memory/auto ptr/dcl list operator auto ptrTemplate:cpp/memory/auto ptr/dcl list getTemplate:cpp/memory/auto ptr/dcl list operator*Template:cpp/memory/auto ptr/dcl list resetTemplate:cpp/memory/auto ptr/dcl list release