Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Standard C++ Library Module Reference Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

auto_ptr

Module:  Standard C++ Library   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

Copyright (c) 1994-2006 Rogue Wave Software, a Quovadx Division.
Licensed under the Apache License, Version 2.0.
Contact Rogue Wave about documentation or support issues. You can also seek help from other developers through the Apache stdcxx community (see below).

For more information on the Rogue Wave Standard C++ Library under open source, see Section 1.2 of the user's guide.