previous | start | next

## Calling the Base-Class Constructor

- The constructor of a derived class has two tasks:
  - Initialize the base object.
  - Initialize all data members.
- Frequently, a derived-class constructor must invoke the base-class constructor before initializing the derived-class data.
- Here, we call the `Clock` constructor with the parameter`mil` before executing the code inside the `{}`.

  >     TravelClock::TravelClock(bool mil, string loc, int diff)
  >        : Clock(mil)
  >     {
  >        location = loc;
  >        time_difference = diff;
  >        while (time_difference < 0)
  >           time_difference = time_difference + 24;
  >     };

- If you omit the base-class constructor, then the base object is constructed with the default constructor of the base class.
- If the base class has no default constructor, then you have to explicitly call the base-class constructor in the derived-class constructor.

previous | start | next