In this recipe, we will learn about why the C++ Core Guidelines discourage the use of manually calling new and delete and why, instead, they recommend the use of std::unique_ptr and std::shared_ptr. We will also learn about the differences between a std::unique_ptr and a std::shared_ptr and why a std::shared_ptr should only be used in certain scenarios (that is, why std::unique_ptr is likely to be the smart pointer type that you should be using in most scenarios). This recipe is important as it will teach you how to properly allocate dynamic (heap) memory in modern C++.
Comparing std::shared_ptr and std::unique_ptr
Getting ready
Before beginning, please ensure that all of the technical requirements have been met, including...