本文介绍了虚拟继承:错误:没有唯一的最终覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道虚拟继承在这之前和之前提到这个问题我经历了虚拟继承的细节,并通过类似的问题,如下所示:

I know virtual inheritance is covered here before and before asking this question I went through the detail of the virtual inheritance and went through the details of a similar problem like the followings:


and
)。但我的没有。它在 Base :: fun der1 :: fun der2 :: fun ?范围操作员是否帮助?

I can see how this issue works (final overrider). But mine doesn't. Is it getting confused between Base::fun, der1::fun and der2::fun? Does the scope operator help in anyway?

任何线索或帮助是值得赞赏的。我使用g ++ 4.6.3。

Any clue or help is appreciated. I am using g++ 4.6.3.

推荐答案

大多数派生类必须提供虚拟函数的实现基类 - 否则如何提供基类接口,给定中间类(即你的 der1 der2 )提供两个选择已经 - 哪一个应该调用?你必须消除歧义(即 der3 :: fun())。

The most-derived class has to provide an implementation of the virtual functions in the virtual base class - otherwise how would it provide that base class interface, given the intermediate classes (i.e. your der1 and der2) provide two alternatives already - which one should it call? You have to disambiguate the situation (i.e. with der3::fun()).

实际上调用 der3 :: fun(),因为你明确要求 base :: fun()这意味着规则不适用,只要你想象你可以实例化一个抽象类,如果你不尝试调用纯虚函数....程序是错误的,直到代码绑定这些松散结束。

Sure you're not actually calling der3::fun() as you're explicitly requesting base::fun(), but that doesn't mean the rules don't apply, any more than thinking you could instantiate an abstract class if you don't try to call the pure-virtual functions.... The program is ill-formed until the code ties off these loose ends.

这篇关于虚拟继承:错误:没有唯一的最终覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 06:17