... Figs. 9.259.27 modifies class Time’s set functions setTime, setHour, setMinute and setSecond such that each returns a reference to the Time object on which it’s called to enable cascaded member-function calls. Notice in Fig. 9.26 that the last statement in the body of each of these member functions returns *this (lines 21, 33, 45 and 57) into a return type of Time&.

Fig. 9.25 Time class modified to enable cascaded member-function calls.

Alternate View

 1   // Fig. 9.25: Time.h
 2   // Time class modified to enable cascaded member-function calls.
 3   #include <string>
 4
 5   // Time class definition.
 6   // Member functions defined in Time.cpp.
 7   #ifndef 

Get C++ How to Program, 10/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.