9.6 FUNCTION OVERRIDING
In Program 9.1 (inher1.cpp), you will notice that we are displaying the time in haphazard manner. Time was displayed using the method show() of the base class Time0 and AM or PM was shown by the code “cout << t.strg << endl;”. Why not to write a method in class clock. Yes, it will be a good idea. What name should we give? show()?, but that name is already in use in class time0, the base class. Here, C++ says that you can use the same name in the derived class.
Consider the code as
class Time0 { protected: int hr; int min; int sec; public : void settime(int h, int m, int s); void show(); };class Clock : public Time0 { private : char strg[5]; // for AM PM public : void ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access