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