EverSpring working shop

To pursue creative ideas based on nature.

统计

留言簿(1)

他山之石

阅读排行榜

评论排行榜

The access label transition during the Public / Protected / Private Inheritance

The base class has already defined the access label for each member of itself.
The access label which is used to control the access from the derived class to the memeber of its base class does not change during the inheritance.
BUT the access label which is used to control the access from the user of the derived class to the member of the base class should be updated according to the rules below:

  1. Public Inheritance:
    • Private -> Private
    • Public -> Public
    • Protected -> Protected
  2. Protected Inheritance:
    • Private -> Private
    • Public -> Protected
    • Protected -> Protected
  3. Privated Inheritance:
    • Private -> Private
    • Public -> Private
    • Protected -> Private

The Private member can only be accessed by the class itself and its friends.

The Protected member can only be accessed by the class itself and its friends and its derived class.

The Public member can be accessed by all kinds of users.

Default Inheritance:
For Class, the derived Class using the class key word has PRIVATE inheritance.
For Struct, the derived Class using the struct key word has PUBLIC inheritance.

posted on 2007-10-21 18:21 everspring79 阅读(147) 评论(0)  编辑 收藏 引用 所属分类: Notes


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理