Access specifiers control the level of access to noninherited class members. The access for an inherited member is controlled in three ways:
Resolution of member names does not depend on the level of access associated with each class member.
Consider the following example:
class A {
private:
int a;
};
class B {
public:
int a;
};
class C : public A, public B {
void f() { a = 0; } // ambiguous - is it A::a or B::a?
};
In this example, class A has a private member a, and class B has a public member a. Class C is derived from both A and B. C does not have access to A::a, but a in the body of f() can still resolve to either A: :a or B::a. For this reason, a is ambiguous in the body of f().
If a class is derived publicly from a base class, a protected static base class member can be accessed by members and friends of any classes derived from that base class. A protected nonstatic base class member can be accessed by members and friends of any classes derived from that base class by using one of the following:
If a class is derived privately from a base class, all protected base class members become private members of the derived class.
![]()
Examples of Inherited Member
Access Rules
![]()
Access Declarations
Access Resolution
Derivation
Derivation Access of Base Classes
Member Access
Pointer