Caffeinated Coder
Book an appointment
Lesson 17 · Classes

Inheritance and virtual functions

A derived class is built on a base class: a Dog is an Animal plus more. Follow one Dog object as main makes it and uses it through a pointer to Animal: watch the Animal part get built before the Dog part, a normal call go where the pointer's type says, a virtual call go where the object really is (through the hidden vptr and vtable), override catch a typo, and the destructors run Dog first, then Animal.

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

Quiz Unlocks after the last step.