gpt4 book ai didi

c++ - 多重继承何时会出现歧义?

转载 作者:太空宇宙 更新时间:2023-11-04 15:09:25 25 4
gpt4 key购买 nike

什么时候多重继承会产生歧义?

最佳答案

当您在多个继承路径中复制了基类并且您正试图对其进行强制转换或调用其成员函数时。

struct A { };
struct B : A { };
struct C : A { };
struct D : B, C { }; // has replicated A as the base class

D d;
A* a = static_cast<A*>(&d); // oops

这个问题有几个严重依赖于上下文的补救措施(使用虚拟基类,只需改进上述转换等)

更多信息 here , 特别是 here .

关于c++ - 多重继承何时会出现歧义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5459146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com