0Pricing
C++ Academy · Lesson

Abstract Classes and Pure Virtual Methods

Define interfaces with pure virtual methods and enforce derived-class contracts.

What is an Abstract Class?

An abstract class has at least one pure virtual function — declared with = 0. You cannot instantiate it directly.

class Animal {
public:
    virtual void speak() const = 0;   // pure virtual
    virtual ~Animal() = default;
};

// Animal a;     // ERROR: cannot instantiate

Pure Virtual Functions

The = 0 marks a function as having no default implementation. Derived classes must override it before the class can be instantiated.

All lessons in this course

  1. Single and Multiple Inheritance
  2. Virtual Functions and the vtable
  3. Abstract Classes and Pure Virtual Methods
  4. Inheritance vs Composition Trade-offs
← Back to C++ Academy