Difference between private, public, and protected inheritance

后端 未结 16 1748
灰色年华
灰色年华 2020-11-21 06:15

What is the difference between public, private, and protected inheritance in C++?

16条回答
  •  清酒与你
    2020-11-21 06:39

    Accessors    | Base Class | Derived Class | World
    —————————————+————————————+———————————————+———————
    public       |      y     |       y       |   y
    —————————————+————————————+———————————————+———————
    protected    |      y     |       y       |   n
    —————————————+————————————+———————————————+———————
    private      |            |               |    
      or         |      y     |       n       |   n
    no accessor  |            |               |
    
    y: accessible
    n: not accessible
    

    Based on this example for java... I think a little table worth a thousand words :)

提交回复
热议问题