O'Reilly logo

Navigating C++ and Object-Oriented Design by Gail Anderson, Paul Anderson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required