Standard C++ Library Class Reference

X*
operator-> () const;
Returns the underlying pointer.
Member Functions
X*
get () const;
Returns the underlying pointer.
X*
release();
Releases ownership of the underlying pointer. Returns that pointer.
void
reset (X* p = 0);
Requires that p points to an object of class X or a class derived from X for which delete p
is defined and accessible, or p is a null pointer. Deletes the current underlying pointer,
then resets it to p.
Example
//
// auto_ptr.cpp
//
#include <iostream.h>
#include <memory>
//
// A simple structure.
//
struct X
{
X (int i = 0) : m_i(i) { }
int get() const { return m_i; }
int m_i;
};
int main ()
{
//
// b will hold a pointer to an X.
//
auto_ptr<X> b(new X(12345));
//
// a will now be the owner of the underlying pointer.