I see that std::unique_ptr
has the following ways of initialization:
std::unique_ptr<some_class> sc_ptr{ new some_class };
wherein someone could delete
the allocated some_class
from underneath the std::unique_ptr
.
and
some_class *scptr { new some_class }
std::unique_ptr<some_class> sc_ptr1{ scptr };
std::unique_ptr<some_class> sc_ptr2{ scptr };
Defeating the purpose of 'unique' in the std::unique_ptr
and also leading to UDB.
Now the question that I have is: Why does the std::unique_ptr
class even allow above methods of initialization while it has the std::make_unique<some_class>()
method at its disposal?
Am I missing something here?