... object’s destructor is called.

Using const and Non-const Member Functions

The program of Fig. 9.17 uses class Time from Figs. 9.59.6, but removes const from function toStandardString’s prototype and definition so that we can show a compilation error. We create two Time objects—non-const object wakeUp (line 6) and const object noon (line 7). The program attempts to invoke non-const member functions setHour (line 11) and toStandardString (line 15) on the const object noon. In each case, the compiler generates an error message. The program also illustrates the three other member-function-call combinations on objects—a non-const member function on a non-const object (line 10), a const member function on a non-const object (line 12) and a const member function ...

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.