One colleague mentioned in the chat; why accessing private inherited base type inside the derived type member function results in access control failure "'BaseType' is a private member of 'BaseType'"?
i.e. https://godbolt.org/z/hWef37sT9
It turns out from the basic name resolution logic in the language which refer to ISO 6.5 : https://timsong-cpp.github.io/cppwp/basic.lookup.unqual
To summarize:
- Name lookup
This is the process by which the compiler determines the meaning of a name, without regard to access permissions. This lookup will find the declaration or definition of the name in the applicable scopes (namespace, class, or enclosing function). - Access control
After name lookup has identified the entity, the compiler checks access control to determine whether it is permissible to use the entity based on access specifiers like public, protected, or private.
In essence, the sequence is:
- First, perform name lookup.
- Then, check access control on the resolved name.
class PrivateBase {
};
class Middle: private PrivateBase {
};
class Child: public Middle {
::PrivateBase Fooey() {
return ::PrivateBase();
}
};