Virtual Inheritance: Error: no unique final overrider

后端 未结 2 1401
情歌与酒
情歌与酒 2020-12-05 07:54

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 sim

2条回答
  •  生来不讨喜
    2020-12-05 08:13

    Using the scope resolution operator to specify that you want to call base::fun doesn't make the error go away because the program would be ill-formed even with an empty main(). You simply are not allowed to have a situation in which a virtual function has more than one final overrider in any derived class that exists in your program.

    Informally, just because trying to call p->fun() would be ambiguous, the program is ill-formed even if you don't do it.

    Note: This is in contrast to the situation you have with overloaded functions, in which potential ambiguity is allowed---perhaps even unavoidable---as long as you avoid a call that actually would be ambiguous. Why are the rules different? Basically it is because even constructing an object of type der3 cannot be done in a sensible way---which version of fun should the vtable point to?

提交回复
热议问题