Smart Pointers

The std::unique_ptr class template is an example of a so-called smart pointer. A smart pointer behaves much like any other pointer but with extra features and functionality. This Exploration takes a closer look at unique_ptr and other smart pointers.

Revisiting unique_ptr

Exploration 61 introduced unique_ptr as a way to manage dynamically allocated objects. The unique_ptr class template overloads the dereference (*) and member access (->) operators and lets you use a unique_ptr object the same way you would use a pointer. At the same time, it extends the behavior of an ordinary pointer, such that when the unique_ptr ...

Get Exploring C++ 11, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.