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. Unfortunately it doesn't work for Gdiplus::Bitmap
std::unique_ptr<Gdiplus::Bitmap> bitmap(new Gdiplus::Bitmap(width, height, PixelFormat32bppARGB)); // Need to use the old way
More Info http://www.google.com/search?q=std::make_unique+examples