The C ++ access control operator has three private, protected, and public.
1. Simple descriptions can be classified into the following two types:
1) A ClassYouyuan (including youyuan functions, member functions of youyuan classes, and all member functions of youyuan classes)You can access anyMember(Including member variables and member methods ).
2) except for friends, privateMemberOnlyTheMember FunctionsAccessible, protectedMemberOnlyClass and its derived classMember FunctionsAccessible, publicMemberThenClass and its derived classMember functions and objectsCan be accessed.
Ii. Impact of the inheritance mode of derived classes
Class inheritance methods include private, protected, and public.
1) Private attributes cannot be inherited.
2) use private inheritance. The protected and public attributes of the parent class are changed to private in the subclass;
Using Protected inheritance, the protected and public attributes of the parent class are changed to protected in the subclass;
Use public inheritance. The protected and public attributes in the parent class are not changed;
As follows:
| |
Public |
Protected |
Private |
| Public inheritance |
Public |
Protected |
Unavailable |
| Protected inheritance |
Protected |
Protected |
Unavailable |
| Private inheritance |
Private |
Private |
Unavailable |
That is, protected inheritance and private inheritance can reduce access permissions.
References:
C ++ class Access Control (Public/protected/private)
C ++ class access control public/private/protected
Access Control in C ++
<End>