Deleting a unique_ptr

I have a unique_ptr that is stored in multiple vectors, and I don't want to manually take it out of scope by removing it from every vector.

Would deleting the object that it POINTS to take the unique_ptr out of scope?
> I have a unique_ptr that is stored in multiple vectors

The semantics of std::unique_ptr is sole ownership of an object.
Do not, repeat do not, create more than one std::unique_ptr pointing to the same object.

For shared ownership semantics, use std::shared_ptr
http://en.cppreference.com/w/cpp/memory/shared_ptr

In either case, let the smart pointer manage object life-time.

In an extreme case, if you are compelled to manually delete an object whose ownership is managed via smart pointers, delete it after asking the smart pointer(s) to release ownership.
http://en.cppreference.com/w/cpp/memory/shared_ptr/reset
http://en.cppreference.com/w/cpp/memory/unique_ptr/release
Topic archived. No new replies allowed.