Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

auto_ptr

Library:  General utilities


Does not inherit

Local Index

Members

Summary

A simple smart pointer class

Synopsis

#include <memory>

namespace std {
  template <class X> class auto_ptr;
}

Description

The class template specialization auto_ptr holds onto a pointer obtained via new() and then deletes that object when the auto_ptr object itself is destroyed. 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

Struct auto_ptr_ref

template <class Y>
struct auto_ptr_ref;

Typedef

typedef X element_type;

Constructors

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

Destructors

~auto_ptr () throw();

Operators

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

Member Functions

X*
get() const throw();
X*
release() throw();
void
reset(X* p = 0) throw();

Example

X::X (12345)

b destroyed

12345

X::~X [12345]

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 20.4.5



Previous fileTop of DocumentContentsIndex pageNext file