August 2012
Intermediate to advanced
976 pages
30h 17m
English
The library smart pointer types (§ 12.1, p. 450) offer a good illustration of design choices faced by designers of templates.
The obvious difference between shared_ptr and unique_ptr is the strategy they use in managing the pointer they hold—one class gives us shared ownership; the other owns the pointer that it holds. This difference is essential to what these classes do.
These classes also differ in how they let users override their default deleter. We can easily override the deleter of a shared_ptr by passing a callable object when we create or reset the pointer. In contrast, the type of the deleter is part ...
Read now
Unlock full access