Time Class Member Functions

In Fig. 9.2, the Time constructor (lines 11–14) initializes the data members to 0—the universal-time equivalent of 12 AM. Invalid values cannot be stored in the data members of a Time object, because the constructor is called when the Time object is created, and all subsequent attempts by a client to modify the data members are scrutinized by function setTime (discussed shortly). Finally, it’s important to note that you can define overloaded constructors for a class—we studied overloaded functions in Section 6.17.

 1   // Fig. 9.2: Time.cpp  2   // Time class member-function definitions.  3   #include <iostream> 4   #include <iomanip> 5   #include <stdexcept> // for invalid_argument exception ...

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.