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)?
你可以使用ptr.get()
如果你想获得指针,然后让auto_ptr
删除它,或者使用ptr.release()
来获取指针并让auto_ptr
忘记它(你必须删除它)然后。)
在auto_ptr上调用release() ,然后可以将值存储在不同的智能指针或原始指针中,并将其与STL容器一起使用。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.