Using Class Time

Once defined, Time can be used as a type in declarations as follows:

Time sunset; // object of type Timearray< Time, 5 > arrayOfTimes; // array of 5 Time objectsTime &dinnerTime = sunset; // reference to a Time objectTime *timePtr = &dinnerTime; // pointer to a Time object

Figure 9.3 uses class Time. Line 11 instantiates a single object of class Time called t. When the object is instantiated, the Time constructor is called to initialize each private data member to 0. Then, lines 15 and 17 print the time in universal and standard formats, respectively, to confirm that the members were initialized properly. Line 19 sets a new time by calling member function setTime, and lines 23 and 25 print the ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.