9.3 PUBLIC DERIVATION

Now consider a practical application. We want to use a computer as a digital clock! For any digital clock, time is the basic building block. It also shows AM/PM. We have already defined and used a class time0. How can we use it to our advantage? Principle of inheritance comes into the picture. We can define a new class called clock based on the previously defined class time0. A new class clock will inherit properties of old class time0.

With public derivation, a typical declaration will look as follows:

class Clock : public Time0

The class definition does the following:

  1. Class clock is defined.
  2. It is derived from an existing class Time0.
  3. The derivation is public. In this example, class Time0 is the base class and class ...

Get Object Oriented Programming with C++, Second Edition 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.