Lesson 1
We've learned about object lifetime and dynamically allocated memory on the heap.
Today, we're going to put the two together by exploring what happens when an instance of a class can manage its own dynamically allocated memory.
This lesson also gives you a chance to get more practice working with pointers!
This lesson addresses aspects of the following course learning goals in Group 5:
- Goal 5A: Model Objects:
- Draw memory models for classes that allocate memory on the heap
- Goal 5D: Constructors and Destructors:
- Write constructors, destructors, and assignment operators, including for classes that allocate memory on the heap.
- Use the keywords
default
anddelete
to control if and how those functions will be synthesized by the compiler.
Outline
- Before You Start…
- Reminder: Defining a Class
- Reminder: Implementing a Class
- When Classes Allocate Memory…
- Initializing Heap Memory in Constructors
- Array Elements that “Don't Have a Cow”
(That's a pretty good chunk of material. Consider taking a breather here.)
- Initializing Heap Memory in Member Functions
- Revisiting the Default Constructor
- Destruction for Custom Classes: Destructors
(Woo-hoo, we have a working class that can be used! This is another good time for a stretch, maybe some fresh air…)
- Providing a Copy Constructor
- Assignment for Custom Classes: Assignment Operators
- Key Points
- Before You Go…
To receive credit: complete all pages above, then this page will be complete as well (and get a green check emoji at the bottom right of the page).
(When logged in, completion status appears here.)