Virtual function inheritance

后端 未结 3 2237
忘掉有多难
忘掉有多难 2021-02-20 00:20

I have a confusion about the inheriting the virtual property of a method.

Let\'s suppose we have 4 classes: class A, class B, class C and class D. The classes are inheri

3条回答
  •  北恋
    北恋 (楼主)
    2021-02-20 00:46

    You are entirely correct. Child inherits what its ancestors have. Base classes can't inherit what the child has (such as a new function or variable). Virtual functions are simply functions that can be overridden by the child class if the that child class changes the implementation of the virtual function so that the base virtual function isn't called.

    A is the base class for B,C,D. B is a the base class for C, D. and C is the base class for D too.

提交回复
热议问题