简体   繁体   English

多级继承C ++

[英]Multilevel inheritance C++

Suppose a class C inherits from a class B which overrides a virtual function defined in A. C does not override the function. 假设一个C类继承自B类,它覆盖了A中定义的虚函数.C不会覆盖该函数。 When a pointer of type A* points to an object of type C, will the function call use the overridden version in B? 当类型A *的指针指向类型C的对象时,函数调用是否会使用B中的重写版本?

Yes! 是!

Semantically, C inherits its implementation from B implicitly. 从语义上讲, C隐式地从B继承其实现。
Concretely, the implementation of a virtual function that's called is the most derived available one. 具体地说,被调用的虚函数的实现是最可用的。

When a pointer of type A* points to an object of type C, will the function call use the overridden version in B? 当类型A *的指针指向类型C的对象时,函数调用是否会使用B中的重写版本?

Yes. 是。

是的函数调用将使用B中的重写版本,除非您在C中实现虚函数。在这种情况下,函数调用将是C.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM