11.2. Public Derivation

C++ has three ways to implement inheritance: public derivation, private derivation, or protected derivation. Only public derivation supports polymorphism, which we will discuss shortly. Each form of derivation has its own access rules between base and derived classes. These access rules affect private and public access, as well as protected access (see “Protected Access” on page 499). Let's begin with public derivation, the simplest and most common form of inheritance, but without protected access. Later on, we'll show you how protected affects the access rules with all derivations.

Here's the format for public derivation.

class Base {
private:
   . . .
public:
   Base(b_args) { . . . }
   . . .
};
class Derived : public Base ...

Get Navigating C++ and Object-Oriented Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.