Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

auto_ptr


Memory Management

Summary

A simple, smart pointer class.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

#include <memory>
template <class X> class auto_ptr;

Description

The template class auto_ptr holds onto a pointer obtained via new and deletes that object when the auto_ptr object itself is destroyed (such as when leaving block scope). auto_ptr can be used to make calls to operator new exception-safe. The auto_ptr class has semantics of strict ownership: an object may be safely pointed to by only one auto_ptr, so copying an auto_ptr copies the pointer and transfers ownership to the destination if the source had already had ownership.

Interface

template <class X> class auto_ptr {
template <class Y> class auto_ptr_ref {
   public:
     const auto_ptr<Y>& p;
     auto_ptr_ref (const auto_ptr<Y>&);
};
   public:
     typedef X element_type;
     // constructor/copy/destroy

     explicit auto_ptr (X* = 0) throw();
     auto_ptr (const auto_ptr<X>&) throw ();
     template <class Y>
       auto_ptr (const auto_ptr<Y>&) throw();
     void operator=(const auto_ptr<X>&) throw():
     template <class Y>
       void operator= (const auto_ptr<Y>&) throw();
     ~auto_ptr ();

     // members

     X& operator* () const throw();
     X* operator-> () const throw();
     X* get () const throw();
     X* release () throw();
     void reset (X*=0) throw();
     auto_ptr(auto_ptr_ref<X>) throw();
     template <class Y>
     operator auto_ptr_ref<Y>() throw();
     template <class Y>
     operator auto_ptr<Y>() throw();
 };

Types

template <class Y>
class auto_ptr_ref;

Constructors

explicit 
auto_ptr (X* p = 0);
auto_ptr (const auto_ptr<X>& a);
template <class Y>
auto_ptr (const auto_ptr<Y>& a);
auto_ptr (const auto_ptr_ref<X> r);

Destructors

~auto_ptr ();

Operators

void operator= (const auto_ptr<X>& a);
template <class Y> 
void operator= (const auto_ptr<Y>& a);
X& 
operator* () const;
X* 
operator-> () const;
template <class Y>
operator auto_ptr_ref<Y> ();
template <class Y>
operator auto_ptr<Y> ();

Member Functions

X* 
get () const;
X*
release();
void
reset(X* p)

Example

Program Output



Previous fileTop of documentContentsIndexNext file
©Copyright 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998