June 2018
Intermediate to advanced
348 pages
8h 45m
English
Managing object lifetimes has been a problematic area for the C++ programming language. If the developer is not careful, the program can leak memory and will slow down performance. Smart pointers are wrapper classes around a raw pointer where operators such as dereferencing (*) and referencing (->) are overloaded. Smart pointers can do object lifetime management, act as a limited form of garbage collection, free memory, and so on. The Modern C++ language has:
A unique_ptr<T> is a wrapper for a raw pointer where there is exclusive ownership with the wrapper. The following code snippet will demonstrate the use of <unique_ptr>:
//---- Unique_Ptr.cpp#include <iostream>#include <deque>#include ...