public member function
<memory>
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).
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
// auto_ptr::reset example
#include <iostream>
#include <memory>
int main () {
std::auto_ptr<int> p;
p.reset (new int);
*p=5;
std::cout << *p << '\n';
p.reset (new int);
*p=10;
std::cout << *p << '\n';
return 0;
}
|
Output: