Access Resolution

Access resolution is the process by which the accessibility of a particular class member is determined. Accessibility is dependent on the context. For example, a class member can be accessible in a member function but inaccessible at file scope. The following describes the access resolution procedure used by the compiler.

In general, two scopes must be established before access resolution is applied. These scopes reduce an expression or declaration into a simplified construct to which the access rules are applied. These scopes are:

Call scope: the scope that encloses the expression or declaration that uses the class member.

Reference scope: the scope that identifies the class.


For example, in the following code:

// This example illustrates access resolution.

class B { public: int member; };        // declaration
class A : B {}                          // declaration
void main()
{
      A aobject;                         // declaration
      aobject.member = 10;               // expression
}

the reference scope for member is the type of aobject, that is class type A. Reference scope is chosen by simplifying the expression (or declaration) containing the member. An expression can be thought of as being reduced to a simple expression of the form obj .member where obj is the reference scope. Reference scope is selected as follows:


The call scope and the reference scope determine the accessibility of a class member. Once these scopes are resolved, the effective access of the member is determined. Effective access is the access of the member as it is seen from the reference scope. It is determined by taking the original access of the member in its scope as the effective access and changing it as the class hierarchy is traversed from the member's class to the reference scope. Effective access is altered as the class hierarchy is traversed for each derivation by the following:

After effective access is determined for a member, the access rules are applied as if the effective access were the original access of the member. A member is only accessible if the access rules say that it is.


Example of Access Resolution


Derivation Access of Base Classes
Access Declarations
Member Access
Derivation
Overloading Functions
Scope Resolution Operator