auto_ptr::reset
La funzione membro valuta l'espressione eliminazione myptr, ma solo se le modifiche archiviate di myptr di valore del puntatore come risultato di una chiamata di funzione. Sostituisce il puntatore archiviato con ptr.
void reset(
Type* _Ptr = 0
);
Parametri
- _Ptr
Il puntatore specificato per sostituire il puntatore archiviato myptr.
Esempio
// auto_ptr_reset.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>
#include <vector>
using namespace std;
class Int
{
public:
Int( int i )
{
x = i;
cout << "Constructing " << ( void* )this << " Value: " << x << endl;
};
~Int( )
{
cout << "Destructing " << ( void* )this << " Value: " << x << endl;
};
int x;
};
int main( )
{
auto_ptr<Int> pi ( new Int( 5 ) );
pi.reset( new Int( 6 ) );
Int* pi2 = pi.get ( );
Int* pi3 = pi.release ( );
if ( pi2 == pi3 )
cout << "pi2 == pi3" << endl;
delete pi3;
}
Requisiti
Header: <memory>
Spazio dei nomi: std