previous | start | next

## Polymorphism

- You will find that there is quite a bit of repetitive code in `clocks2.cpp`.
- It would be nicer if all three clocks were collected in a vector.

  >     vector<Clock> clocks(3);
  >     clocks[0] = Clock(true);
  >     clocks[1] = TravelClock(true, "Rome", 9);
  >     clocks[2] = TravelClock(false, "Tokyo", -7);

  >     for(int i = 0; i < clocks.size(); i++)
  >     {
  >        cout << clocks[i].get_location() << " time: "
  >           << clocks[i].get_hours() << ":"
  >           << setw(2) << setfill('0'
  >           << clocks[i].get_minutes()
  >           << setfill(' ') << "\n";
  >     }

- Unfortunately, that does not work.

previous | start | next