What happens when redirecting unique_ptr?

Viewed 1016

I understand that unique_ptr is a single owner of some object and it deallocates that object when it goes out of scope. What I don't understand is the following situation:

unique_ptr<int> p(new int(1));
p = unique_ptr<int>(new int(2));

What happens with the first object new int(1) if p is redirected to another memory location new int(2) (since p can own only one of those)?

2 Answers
Related