< previous page page_858 next page >

Page 858
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
This comment reminds the reader that any references to these identifiers are references to the private class members.
3. In the heading of each function definition, the name of the member function is prefixed by the class name (TimeType) and the C++ scope resolution operator (::). As we discussed earlier, it is possible for several different classes to have member functions with the same name, say, Write. In addition, there may be a global Write function that is not a member of any class. The scope resolution operator eliminates any uncertainty about which particular function is being defined.
4. Although clients of a class must use the dot operator to refer to class members (for example, startTime.Write()), members of a class refer to each other directly without using dot notation. Looking at the bodies of the Set and Increment functions, you can see that the statements refer directly to the member variables hrs, mins, and secs without using the dot operator.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
An exception to this rule occurs when a member function manipulates two or more class objects. Consider the Equal function. Suppose that the client code has two class objects, startTime and endTime, and uses the statement
if (startTime.Equal(endTime))
    .
    .
    .
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
At execution time, the startTime object is the object for whom the Equal function is invoked. In the body of the Equal function, the relational expression
hrs == otherTime.hrs
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
refers to class members of two different class objects. The unadorned identifier hrs refers to the hrs member of the class object for whom the function is invoked (that is, startTime). The expression otherTime.hrs refers to the hrs member of the class object that is passed as a function parameter: endTime.
5. Write, Equal, and LessThan are observer functions; they do not modify the private data of the class. Because we have declared these to be const member functions, the compiler will prevent them from assigning new values to the private data. The use of const is both an aid to the user of the class (as a visual signal that this function does not modify any private data) and an aid to the class implementor (as a way of preventing accidental modification of the data). Note that the word const must appear in both the function prototype (in the class declaration) and the heading of the function definition.

 
< previous page page_858 next page >