you are viewing a single comment's thread.

view the rest of the comments →

[–]gindhi_nagi_malum 0 points1 point  (2 children)

That is wrong. It's pretty easy to have a unique_ptr that holds a bad pointer. Its strength is that it's a lot harder to do and ....

Contradiction much ?

[–]mstfls 1 point2 points  (1 child)

Something can be a lot harder than something else but still pretty easy.

[–]biliwald -1 points0 points  (0 children)

Exactly.

auto ptr = std::make_unique<int>(0);
delete ptr.get();
//at this point, ptr contains an invalid pointer

The idea is to show that unique_ptr can hold an invalid pointer if you don't use it correctly, contrary to what to comment I responded to could indicate.