9.8 END OF CHAPTER PROGRAMS

9.8.1 Working with private derivation

Earlier, we had compile time error with private derivation. We can modify that Program 9.2 (private2.cpp), therefore, it works fine. Well, this is only working indirectly. We do not recommend this as a standard programming practice.

Problem: Rewrite Program 9.2 such that we could access private members of the base class.

Solution: See Program 9.5.

Program 9.5 Private derivation

// private3.cpp#include<IOSTREAM.H>#include<string.h>class Time0{ private:    int min;    int sec;  public :    int hr;    void setTime(int h ,int m , int s);    void show();} ;class Clock : private Time0{ private:    char strg[5]; // for AM PMpublic :    void defineTime(int h1, int m1, int s1);    void ...

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.