Abstract Classes and Virtual Functions

Lesson 18 of 20

Shapes that refuse to be built — pure virtual methods force every child class to earn its concrete form.

The big picture

Contracts, not objects

An abstract class is a promise: "every child of mine will know how to do this." It never runs itself.

Abstract class

Has at least one pure virtual method — you cannot create objects of it, only point at its children.

Pure virtual: = 0

virtual void draw() = 0; has no body. It says: children must implement this, no exceptions.

Concrete child

A child that implements every pure virtual becomes buildable — Circle can finally exist.

Why bother?

The base defines WHAT every child must do; each child decides HOW. Mistakes fail at compile time.