Difference between public/private/protected ACL, privateprotected
// Differences between public/private/protected access control permissions
// Time: 2016/8/16 // (1) modifier: // public: can be used both inside and outside the class. // Protected: Used in the class and inherited subclass. // Private: it can only be used inside a class. // (2) modify the inheritance relationship: // public: The member of the subclass can access the public/protected member of the parent class. // The subclass object can access the public member of the parent class. // Private: The subclass member can access the public/protected member of the parent class. // The subclass object cannot access any member of the parent class. // Protected: The subclass member can access the public/protected member of the parent class. // The subclass object cannot access any member of the parent class. # Include "stdafx. h "# include" iostream "using namespace std; class Parent {public: int a; // the old name protected: int B; // the old bank password private: int c; // The father's lover}; // the inheritance of protection, family. Class Child1: protected Parent {public: protected: public: void useVar () {a = 0; // public OK B = 0; // protected OK // c = 5; // Private not OK }}; // Private inheritance, common. Class Child2: private Parent {public: void useVar () {a = 0; // public OK B = 0; // protected OK // c = 0; // Private not OK }}; // public inheritance, common. Class Child3: public Parent {public: void useVar () {a = 0; // public OK B = 0; // protected OK // c = 0; // Private not OK }}; int main () {Child1 c1; // protection inheritance, family. Child2 c2; // Private inheritance, common. Child3 c3; // common inheritance. // C1.a = 6; // Private not OK // c2.a = 6; // protection not OK c3.a = 6; // public OK return 0 ;}