Modern C++¶
Smart pointers¶
Added in C++11, smart pointers completely replace the old asterisk *
pointer from C. All usage of classic pointers should be replaced with smart pointers as they’re safer: their behavior is more specific and conveys correct usage to the programmer more clearly. Restricted freedom also means that it will allow to catch errors quicker with error handling.
std::unique_ptr
¶
This smart pointer should be used in all occasions where access is limited to only one pointer object. This means that you cannot create multiple unique pointers referencing the same object (please don’t write code that tries to do that, as it will […]). If you dereference a unique pointer, it will automatically deallocate the data it was pointing to.
[…]