J
Jamie Burns
Hello,
I realise that I just dont get this, but I cannot see the need for auto_ptr.
As far as I have read, it means that if you create an object using an
auto_ptr, instead of a raw pointer, then the object will get cleaned up when
the method/function ends. Isn't this what happens if you just declare an
object without using a pointer at all? Aren't these examples the same (I
know they will not be, but I am hoping someone may explain to me what I am
missing here!):
void f()
{
T t;
t.SomeFunc();
} // cleanup when function ends
void f()
{
auto_ptr<T> pt(new T);
pt->SomeFunc();
} // cleanup when function ends
Wish I could see what is going on here!
Jamie.
I realise that I just dont get this, but I cannot see the need for auto_ptr.
As far as I have read, it means that if you create an object using an
auto_ptr, instead of a raw pointer, then the object will get cleaned up when
the method/function ends. Isn't this what happens if you just declare an
object without using a pointer at all? Aren't these examples the same (I
know they will not be, but I am hoping someone may explain to me what I am
missing here!):
void f()
{
T t;
t.SomeFunc();
} // cleanup when function ends
void f()
{
auto_ptr<T> pt(new T);
pt->SomeFunc();
} // cleanup when function ends
Wish I could see what is going on here!
Jamie.