Pointer to auto_ptr instead of a classical double pointer
Posted
by Pin
on Stack Overflow
See other posts from Stack Overflow
or by Pin
Published on 2010-04-29T07:57:53Z
Indexed on
2010/04/29
8:07 UTC
Read the original article
Hit count: 374
c++
|smart-pointers
Hello. I'm quite new to smart pointers and was trying to refactor some existing code to use auto_ptr. The question I have is about double pointers and their auto_ptr equivalent, if that makes sense.
I have a function that accepts a double pointer as its parameter and the function allocates resources for it:
void foo ( Image** img ) { ... *img = new Image(); ...}
This function is then used like this:
Image* img = NULL;
foo ( &img );
...
delete img;
I want to use auto_ptr to avoid having to call delete explicitly. Is the following correct?
void foo ( auto_ptr<Image>* img );
and then
auto_ptr<Image> img = NULL;
foo ( &img );
Thanks.
© Stack Overflow or respective owner