Inheriting private members in C++

前端 未结 7 1954
不知归路
不知归路 2020-12-02 23:59

suppose a class has private data members but the setters and getters are in public scope. If you inherit from this class, you can still call those setters and getters -- ena

7条回答
  •  既然无缘
    2020-12-03 00:26

    It depends on the inheritance type. If you inherit privately, then the derived class does NOT have access to the Base's private members.

    Access                      public     protected    private
    -----------------------------------------------------------
    members of the same class      yes           yes        yes
    members of derived classes     yes           yes         no
    not members                    yes            no         no
    

提交回复
热议问题