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:
See also
- auto_ptr::release
- Release pointer (member function)
- auto_ptr::operator=
- Release and copy auto_ptr (public member function)
- auto_ptr::get
- Get pointer (public member function)