virtual function in private or protected inheritance

前端 未结 5 2210
予麋鹿
予麋鹿 2021-02-12 22:52

It\'s easy to understand the virtual function in public inheritance. So what\'s the point for virtual function in private or protected inheritance?

For example:

5条回答
  •  盖世英雄少女心
    2021-02-12 23:20

    Both private and protected inheritance allow overriding virtual functions in the private/protected base class and neither claims the derived is a kind-of its base.

    Protected inheritance allows derived classes of derived classes to know about the inheritance relationship and still override the virtual functions.

    Privately inheriting from the Base class in your Derived class, destroys all conceptual ties between the derived and base class. The derived class is just implemented in terms of the base class, nothing more. Private inheritance is just an implementation technique and implies no relationship between the classes involved.

提交回复
热议问题