auto_ptr::reset

仅当由于存储区的指针值 myptr 更改函数调用,成员函数计算表达式 deletemyptr,但。它将 ptr然后替换存储的指针。

void reset(
   Type* _Ptr = 0
);

参数

  • _Ptr
    指定的指针替换存储的指针 myptr

示例

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

要求

标头: <memory>

命名空间: std

请参见

参考

auto_ptr Class