liveBook · Manning

Abstract class

As explained in 100 C++ Mistakes and How to Avoid Them

An abstract base class is a C++ base class intended to define behavior for derived classes and not to be instantiated directly.

An abstract class defines shared behavior for derived classes without allowing direct instances. It is a safer starting point than forcing related-looking classes into an incorrect inheritance relationship. section 7.9

A sound abstract base class should:

  • Define behavior common to every derived class, with at least one pure virtual function. section 7.9
  • Allow each derived class to enforce its own class invariant. section 7.9
  • Support substitutability: every derived class must meaningfully implement the base interface. section 7.9

How 100 C++ Mistakes and How to Avoid Them covers it

How deep it goes
Explains pure virtual behavior, class invariants, and substitutability through contrasting C++ designs.
Examples
Uses Shape, Rectangle, and Square, contrasting a valid sibling hierarchy with improper Rectangle–Square inheritance.
What it assumes
Assumes basic inheritance and class-invariant reasoning while teaching how to separate shared interfaces from concrete constraints.
What you can do after
Evaluate inheritance designs by testing substitutability, defining shared behavior, and preserving each derived class's constraints.
How it connects
Connects abstract classes with inheritance, pure virtual functions, class invariants, substitutability, and code reuse.

Also explained in

Compare how 6 books explain abstract class →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 C++ Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.