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::reset

public member function
void reset (X* p=0) throw();

Deallocate object pointed and set new value

Destructs the object pointed by the auto_ptr object, if any, and deallocates its memory (by calling operator delete). If a value for p is specified, the internal pointer is initialized to that value (otherwise it is set to the null pointer).

To only release the ownership of a pointer without destructing the object pointed by it, use member function release instead.

Parameters

p
Pointer to element. Its value is set as the new internal pointer's value for the auto_ptr object.
X is auto_ptr's template parameter (i.e., the type pointed).
none

Return value

none


Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// auto_ptr::reset example
#include <iostream>
#include <memory>
using namespace std;
int main () {
  auto_ptr<int> p;
  p.reset (new int);
  *p=5;
  cout << *p << endl;
  p.reset (new int);
  *p=10;
  cout << *p << endl;
  return 0;
}


Output:

5
10

See also