7. Ownership and Lifetime of Dynamic Variables
Overview
This chapter provides tools and strategies to make the use of pointers and dynamic variables in C++ programs safer and easier to understand. By the end of this chapter, you will be able to describe the weaknesses of C++ with respect to dynamic variable ownership and lifetime; explain the use of owned and unowned pointers; embed pointers into class instances to establish ownership and control the lifetime of dynamic variables; use smart pointer classes unique_ptr<> and shared_ptr<> to automate the ownership and lifetime of dynamic variables.
Introduction
In the previous chapter, we learned how to create and delete dynamic variables and dynamic arrays. We also learned at least seven ...
Get The C++ Workshop now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.