Programming Tips - C++: use std::make_unique() instead of new operator

Date: 2023jan3 Language: C++ Since: C++14 Q. C++: use std::make_unique() instead of new operator A. Its the safer way. The old way
std::unique_ptr<MyObject> a(new MyObject(...));
The new way
std::unique_ptr<MyObject> a = std::make_unique<MyObject>(MyObject(...));
As you can see, it creates a unique_ptr to your object. More Info http://www.google.com/search?q=std::make_unique+examples