auto_ptr::auto_ptr
Il costruttore per oggetti di tipo auto_ptr.
explicit auto_ptr(
Type* _Ptr = 0
) throw( );
auto_ptr(
auto_ptr<Type>& _Right
) throw( );
auto_ptr(
auto_ptr_ref<Type> _Right
) throw( );
template<class Other>
auto_ptr(
auto_ptr<Other>& _Right
) throw( );
Parametri
_Ptr
Il puntatore all'oggetto che incapsula auto_ptr._Right
L'oggetto di auto_ptr da copiare dal costruttore.
Note
Il primo file _Ptr in myptr, archiviato il puntatore all'oggetto allocato. Il secondo costruttore trasferisce la proprietà del puntatore archiviato in _Right, archiviando _Right.rilascio in myptr.
Il terzo costruttore si comporta come il secondo, con la differenza che archivia right.ref.rilascio in myptr, dove ref costituisce il riferimento archiviato in _Right.
Il costruttore del modello si comporta come il secondo costruttore, a condizione che un puntatore a Altro in modo implicito essere convertito in un puntatore a Tipo.
Esempio
// auto_ptr_auto_ptr.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>
#include <vector>
using namespace std;
class Int
{
public:
Int(int i)
{
cout << "Constructing " << ( void* )this << endl;
x = i;
bIsConstructed = true;
};
~Int( )
{
cout << "Destructing " << ( void* )this << endl;
bIsConstructed = false;
};
Int &operator++( )
{
x++;
return *this;
};
int x;
private:
bool bIsConstructed;
};
void function ( auto_ptr<Int> &pi )
{
++( *pi );
auto_ptr<Int> pi2( pi );
++( *pi2 );
pi = pi2;
}
int main( )
{
auto_ptr<Int> pi ( new Int( 5 ) );
cout << pi->x << endl;
function( pi );
cout << pi->x << endl;
}
Requisiti
Header: <memory>
Spazio dei nomi: std