I have some third party libraries that generate and return an auto_ptr. However, I really want to use some STL containers.
So I’m guessing one way would be to convert
auto_ptr <int> ptr = some_library_call ();
into a regular c++ pointer. Will the following work?
int* myptr = ptr;
If not, what is the best way to use STL with auto_ptr (yes I know it won’t work directly… I’m aware that stl and auto_ptr don’t mix together)?
You can use either
ptr.get()if you want to obtain the pointer and still let theauto_ptrto delete it afterwards, or useptr.release()to obtain the pointer and make theauto_ptrforget about it (you have to delete it afterwards.)