1. class Int   
  2. {  
  3. public:  
  4.    Int(int i)   
  5.    {  
  6.       cout << "Constructing " << ( void* )this  << endl;   
  7.       x = i;  
  8.       bIsConstructed = true;  
  9.    };  
  10.    ~Int( )   
  11.    {  
  12.       cout << "Destructing " << ( void* )this << endl;   
  13.       bIsConstructed = false;  
  14.    };  
  15.    Int &operator++( )   
  16.    {  
  17.       x++;  
  18.       return *this;  
  19.    };  
  20.    int x;  
  21. private:  
  22.    bool bIsConstructed;  
  23. };  
  24.  
  25. void function ( auto_ptr<Int> &pi )  
  26. {  
  27.    ++( *pi );  
  28.    auto_ptr<Int> pi2( pi );  
  29.    ++( *pi2 );  
  30.    pi = pi2;  
  31. }  
  32.  
  33. int main( )   
  34. {  
  35.    auto_ptr<Int> pi ( new Int( 5 ) );  
  36.    cout << pi-><< endl;  
  37.    function( pi );  
  38.    cout << pi-><< endl;  
  39.