Names used with the binary scope-resolution operator (::) are called “qualified names.” The name specified after the binary scope-resolution operator must be a member of the class specified on the left of the operator or a member of its base class(es).
Names specified after the member-selection operator (. or –>) must be members of the class type of the object specified on the left of the operator or members of its base class(es). Names specified on the right of the member-selection operator (–>) can also be objects of another class type, provided that class defines an overloaded member-selection operator (–>) that evaluates to a pointer to the original class type. (This provision is discussed in more detail in “Class Member Access” in Chapter 12, on page 363.)
The compiler searches for names in the following order:
1.Current block scope if name is used inside a function; otherwise global scope.
2.If the name is not found in the current block scope, the compiler searches outward through each enclosing block scope, including the outermost function scope (which includes function arguments).
3.If the name is still not found, and the name is used inside a member function, class's scope is searched for the name.
4.If the name is still not found, the class's base classes are searched for the name.
5.If the name is still not found, the enclosing nested class scope (if any) and its bases are searched. The search continues until the outermost enclosing class scope is searched.
6.If the name is still not found, global scope is searched.
However, you can make modifications to this search order as follows:
1.Names preceded by :: force the search to begin at global scope.
2.Names preceded by the class, struct, and union keywords force the compiler to search only for class, struct, or union names.
3.Names on the left side of the scope-resolution operator (::) can be only class, struct, or union names.
If the name refers to a nonstatic member but is used in a static member function, an error message is generated. If the name refers to any nonstatic member in an enclosing class, an error message is generated because enclosed classes do not have enclosing-class this pointers.