C ++ three kinds of inheritance

 

 

public:  when public inheritance, access to property and the protection of members of the public members of the base class is unchanged, the new members of the derived class can access public members and protected members of the base class, but can not access the private members of the base class. Object of a derived class can only access public members of the derived class (including inherited members of the public), the protection of members and can not access private members.

protected:  the protection of inheritance, and protect members of the public members of the base class become protected members of the derived class after inheritance, the new members of the derived class can access public members and protected members of the base class, but can not access the private members of the base class. Object of a derived class can not access the public members of the derived class inherits the base class, protected members and private members.

private:  after when private inheritance, and protect members of the public members of the base class are inherited derived class become private members, new members of the derived class can access public members and protected members of the base class, but can not access the private base class member. Object of a derived class can not access the public members of the derived class inherits the base class, protected members and private members.

Summary: No matter what kind of inheritance, derived class new members can access public members and protected members of the base class can not access private members. The impact of inheritance is a member of the derived class inherits access attributes, using friend (friend) can access the protected members and private members.

 

 

Links: https://blog.csdn.net/sxtdzj/article/details/81906504

Guess you like

Origin www.cnblogs.com/NiBosS/p/12152272.html