auto_ptr::release

成员用 Null 值替换存储指针的指针 myptr 并返回以前存储的指针。

Type *release( ) throw( );

返回值

先前存储的指针。

备注

成员用 Null 值替换存储指针的指针 myptr 并返回以前存储的指针。

示例

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

要求

页眉: <内存>

命名空间: std

请参见

参考

auto_ptr 类