Summary of public, protected, and private access labels in C ++
First, the access range of the private, public, and protected access labels.Private: It can only be accessed by 1. functions in this class, 2. Other functions. Cannot be accessed by any other user, nor can the object of this class be accessed.
Protected: it can be accessed by 1. functions in this class, 2. Sub-class functions, and 3. Its membership functions. But cannot be accessed by objects of this class.
Public: it can be accessed by 1. functions in this class, 2. Sub-class functions, 3. Its friends functions, or 4. objects in this class. Note: There are three types of functions: normal non-member functions set as friends, member functions of other classes set as friends, and all member functions in the friends class.
Second, the method property changes after the class is inherited.Private attributes cannot be inherited.
Using 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. See the following: public: protected: private:
Public inherits from public protected and is unavailable.
Protected inherits protected. protected is unavailable.
Private inherits private unavailability
Protected inheritance and private inheritance can reduce access permissions.
This article is from the "going straight to" blog, please be sure to keep this source http://cnmtjp.blog.51cto.com/204390/36548