10.1 MULTIPLE INHERITANCE

It is possible for a class to derive features from two base classes. We call it as multiple inheritance. Figure 10.1 illustrates the point.

 

images

 

Figure 10.1 Multiple inheritance

Multiple inheritance can best be illustrated with the example of a digital clock. A digital clock derives time from one class and date from another. We have a class Date and class Time1 developed previously. The new class clock will inherit properties from both these classes. This is shown in Figure 10.2.

Notice the declaration.

class Clock: public Time1 , public Date

This declaration allows all parameters of Time1 and Date to be inherited in ...

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.