[LC++]STL and auto_ptr woes

Jack Lloyd lloyd at acm.jhu.edu
Wed Mar 13 03:44:04 UTC 2002


On Mon, 4 Mar 2002, Charles Randle wrote:

> However when I assign the pointers to an auto_ptr object as in:
>
> ::std::auto_ptr<someobject1> vb = BigMap2["located"].second.first;
>
> the compiler gives the following error:
>
> simple.cpp:52:conversion from 'someobject1*' to non-scalar type
> 'std::auto_ptr<someobject1>' requested

I don't see why you would want to do that, *unless* you want the objects
deleted when you exit the function you are creating the auto_ptr in. If
that is the case, you should remember to remove said objects from the map,
otherwise, when you delete the remaining objects in the map, you'll delete
that object twice, once when the auto_ptr goes out of scope and once when
the map is cleaned out.
-Jack





More information about the tuxCPProgramming mailing list