March 2018
Intermediate to advanced
183 pages
2h 34m
English
Several smart pointer classes were added in C++11 for managing dynamically allocated memory. By using these container classes, instead of raw pointers, it is no longer necessary to manually delete objects created with the new keyword. This simplifies coding by helping to prevent memory leaks.
The first smart pointer that we look at is the unique pointer (std::unique_ptr), which simply acts as a container for a raw pointer. It replaces another deprecated smart pointer named auto_ptr, which was removed in C++17. Consider the following example on how to use a unique pointer. ...