|
|
|
|
|
|
|
time2.Write(); // Outputs 0:0:0 EST
cout << endl;
time2.Set(16, 49, 23, CDT);
time2.Write(); // Outputs 16:49:23 CDT
cout << endl;
time1.Increment();
time1.Increment(); // Outputs 08:35:02 PST
time1.Write();
cout << endl;
.
.
. |
|
|
|
|
|
|
|
|
Implementation of the ExtTime Class |
|
|
|
|
|
|
|
|
The implementation of the ExtTime class needs to deal only with the new features that are different from Time. Specifically, we must write code to override the Set and Write functions and we must write the two constructors. |
|
|
|
|
|
|
|
|
With derived classes, constructors are subject to special rules. At run time, the base class constructor is implicitly called first, before the body of the derived class's constructor executes. Additionally, if the base class constructor requires parameters, these parameters must be passed by the derived class's constructor. To see how these rules pertain, let's examine the implementation file exttime.cpp (see Figure 16-6). |
|
|
|
|
|
|
|
|
Figure 16-6 ExtTime Implementation File |
|
|
|
|
|
|
|
|
//******************************************************************
// IMPLEMENTATION FILE (exttime.cpp)
// This file implments the ExtTime member functions.
// The Time class is a public base class of ExtTime
//******************************************************************
#include exttime.h
#include < iostream.h>
// Additional private members of class:
// ZoneType Zone;
//******************************************************************
ExtTime::ExtTime( /* in */ int initHrs,
/* in */ int initMins,
/* in */ int initSecs,
/* in */ ZoneType initZone )
:Time(initHrs, iniMins, iniSecs)
// Constructor |
|
|
|
|
|