9.4 Class Scope and Accessing Class Members

A class’s data members and member functions belong to that class’s scope. Nonmember functions are defined at global namespace scope, by default. (We discuss namespaces in more detail in Section 23.4.)

Within a class’s scope, class members are immediately accessible by all of that class’s member functions and can be referenced by name. Outside a class’s scope, public class members are referenced through

  • an object name,

  • a reference to an object, or

  • a pointer to an object

We refer to these as handles on an object. The handle’s type enables the compiler to determine the interface (e.g., the member functions) accessible to the client via that handle. [We’ll see in Section 9.14 that an implicit handle ...

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.