Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
Miscellaneous
complex
exception
functional
iterator
limits
locale
memory
new
numeric
stdexcept
typeinfo
utility
valarray
memory
classes:
allocator
auto_ptr
auto_ptr_ref
raw_storage_iterator
functions:
get_temporary_buffer
return_temporary_buffer
uninitialized_copy
uninitialized_fill
uninitialized_fill_n
auto_ptr
auto_ptr::auto_ptr
auto_ptr::~auto_ptr
member functions:
auto_ptr::get
auto_ptr::operator*
auto_ptr::operator->
auto_ptr::operator=
auto_ptr::operator
auto_ptr::release
auto_ptr::reset


auto_ptr::release

member function
X* release() throw();

Release pointer

Sets the auto_ptr internal pointer to null pointer (which indicates it points to no object) without destructing the object currently pointed by the auto_ptr.

To force a destruction of the object pointed, use member function reset() instead.

The function returns a pointer to the object it pointed before the call, which is no longer its responsibility to destruct.

Parameters

none

Return value

A pointer to the element pointed by the auto_ptr object before the call. After the call, the internal pointer's value is the null pointer (points to no object).
X is auto_ptr's template parameter (i.e., the type pointed).


Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// auto_ptr::release example
#include <iostream>
#include <memory>
using namespace std;
int main () {
  auto_ptr<int> auto_pointer (new int);
  int * manual_pointer;
  *auto_pointer=10;
  manual_pointer = auto_pointer.release();
  cout << "manual_pointer points to " << *manual_pointer << "\n";
  // (auto_pointer is now null-pointer auto_ptr)
  delete manual_pointer; 
  return 0;
}


Output:

manual_pointer points to 10

See also