开发者

Visibility modes in Classes

We know that private members are not inherited whenever we inhe开发者_StackOverflow社区rit a base class to get a derived class, but is it possible for derived class member functions to access the private members of the base class?


Private members are inherited, but they are not accessible. They are "private" for a reason. However, if your derived class needs to access them, it should be declared a friend to the base class.


Private members of the base class are inherited by the derived class, but are not (directly) accessible to it. They may still be accessed by protected and public members of the base class. As Hosam Aly says above one could access base class members by making derived class functions friends of the base class, or by turning the private members of the base class into protected members of the base class, whichever is preferable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜