Standard C++ Library Reference ISO/IEC (VERSION3)
~auto_ptr();
template<class Other>
operator auto_ptr<Other>() throw();
template<class Other>
operator auto_ptr_ref<Other>() throw();
template<class Other>
auto_ptr<Ty>& operator=(auto_ptr<Other>& right) throw();
auto_ptr<Ty>& operator=(auto_ptr<Ty>& right) throw();
Ty& operator*() const throw();
Ty *operator->() const throw();
Ty *get() const throw();
Ty *release() const throw();
void reset(Ty *ptr = 0);
};
The class describes an object that stores a pointer to an allocated object myptr of type Ty *.
The stored pointer must either be null or designate an object allocated by a new expression. An
object constructed with a non-null pointer owns the pointer. It transfers ownership if its stored
value is assigned to another object. (It replaces the stored value after a transfer with a null
pointer.) The destructor for auto_ptr<Ty> deletes the allocated object if it owns it. Hence, an
object of class auto_ptr<Ty> ensures that an allocated object is automatically deleted when
control leaves a block, even via a thrown excepiton. You should not construct two
auto_ptr<Ty> objects that own the same object.
You can pass an auto_ptr<Ty> object by value as an argument to a function call. You can
return such an object by value as well. (Both operations depend on the implicit construction of
intermediate objects of class auto_ptr_ref<Ty>, by various subtle conversion rules.) You
cannot, however, reliably manage a sequence of auto_ptr<Ty> objects with an STL
container.
auto_ptr::auto_ptr
explicit auto_ptr(Ty *ptr = 0) throw();
auto_ptr(auto_ptr<Ty>& right) throw();
auto_ptr(auto_ptr_ref<Ty> right) throw();
template<class Other>
auto_ptr(auto_ptr<Other>& right) throw();
The first constructor stores ptr in myptr, the stored pointer to the allocated object. The second
constructor transfers ownership of the pointer stored in right, by storing right.release()
in myptr. The third constructor behaves the same as the second, except that it stores
right.ref.release() in myptr, where ref is the reference stored in right.
The template constructor behaves the same as the second constructor, provided that a pointer to
Other can be implicitly converted to a pointer to Ty.