Hello everyone,
Auto_ptr is convenient because of it saves our work and provides a
framework to auto-management life cycle to reduce potential resource
leak.
But why do we sometimes need to call release method on auto_ptr to go
back to the style of manual management? Remember, when we call release,
we need to delete the object instance manually later.
(here is a sample I modified from MSDN auto_ptr sample code)
Code:
--------------------
// 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 ) );
Int* pi3 = pi.release ();
delete pi3;
}
--------------------
thanks in advance,
George
Cholo Lennon - 19 Feb 2008 12:07 GMT
> Hello everyone,
>
[quoted text clipped - 45 lines]
> thanks in advance,
> George
Again with multiposting... It seems that you can understand the wide range
topic answers that people give you, but you are unable to understand a simple
concept.. multiposting.. The question is: Are you testing our patience? FYI,
http://www.blakjak.demon.co.uk/mul_crss.htm
--
Cholo Lennon
Bs.As.
ARG