The base class has already defined the access label for each member of itself.
The access label which is used to control the access from the derived class to the memeber of its base class does not change during the inheritance.
BUT the access label which is used to control the access from the user of the derived class to the member of the base class should be updated according to the rules below:
- Public Inheritance:
- Private -> Private
- Public -> Public
- Protected -> Protected
- Protected Inheritance:
- Private -> Private
- Public -> Protected
- Protected -> Protected
- Privated Inheritance:
- Private -> Private
- Public -> Private
- Protected -> Private
The Private member can only be accessed by the class itself and its friends.
The Protected member can only be accessed by the class itself and its friends and its derived class.
The Public member can be accessed by all kinds of users.
Default Inheritance:
For Class, the derived Class using the class key word has PRIVATE inheritance.
For Struct, the derived Class using the struct key word has PUBLIC inheritance.