Aracılığıyla paylaş


auto_ptr::reset

Üye işlev deyimi değerlendirir silmekmyptr, ancak yalnızca saklı işaretçi değeri myptr değişikliklerin sonucu olarak bir işlev çağrısı. Daha sonra saklı işaretçisi ile değiştirir ptr.

void reset(
   Type* _Ptr = 0
);

Parametreler

  • _Ptr
    Belirtilen saklı işaretçiyi değiştirmek için işaretçiyi myptr.

Örnek

// 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;
}
  

Gereksinimler

Başlık: <memory>

Namespace: std

Ayrıca bkz.

Başvuru

auto_ptr Class