11.3. Implicit variable access

Actually, the new version of Time::print is more complicated than it needs to be. We don’t really need to create a local variable in order to refer to the instance variables of the current object.

If the function refers to hour, minute, or second, all by themselves with no dot notation, C++ knows that it must be referring to the current object. So we could have written:

void Time::print () {
  cout << hour << ":" << minute << ":" << second << endl;
}

This kind of variable access is called implicit because the name of the object does not appear explicitly. Features like this are one reason member functions are often more concise than nonmember functions.

You have attempted of activities on this page