ptr_vector<A>::release returns a ptr_vector<A>::auto_type , which is a kind of light smart pointer, when the auto_type element goes out of scope, what it indicates is automatically deleted. To restore the raw pointer to an item and not delete it with auto_ptr , which holds it, you also need to call release :
int main() { ptr_vector<A> v; v.push_back(new A); A *temp=v.release(v.begin()).release(); delete temp; return 0; }
The first release tells ptr_vector to abandon it; the second tells auto_ptr also abandon it.
Head geek
source share