Caffeinated Coder
Book an appointment
Lesson 12 · Classes

Classes: objects and their lifetime

A class is a blueprint for a type of your own: it bundles data with the functions that work on it, and it guards that data. Follow a small class, Tally, as main makes two objects from it: watch the constructor fill each object's memory, a member function change it, private keep outside code away, and the destructor run by itself when each object's scope ends, newest first. That fixed timing is the idea behind RAII.

11 min10 steps5 questionsIntermediate
Fig 12 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.