大佬教程收集整理的这篇文章主要介绍了c – 多重继承模糊基类,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
struct Base{}; struct Derived: public Base{}; struct A: public Base{}; struct B: public A,public Base{}; struct C: public A,public Derived{}; // why no ambiguity here? int main() {}
编译器(g 5.1)警告
我明白这一点,基地在B.
>为什么C没有警告? C和C都不继承,它们都继承自Base?
>为什么添加虚拟
struct Derived: virtual Base{};
结果现在B和C发出警告,生活在Wandbox
struct Base { int x; }; struct B: public A,public Base { void foo() { int& x1 = A::x; // OK int& x2 = x; // ambiguous // no way to refer to the x in the direct base } };
struct C: public A,public Derived { void foo() { int& x1 = A::x; // OK int& x2 = Derived::x; // OK } };
以上是大佬教程为你收集整理的c – 多重继承模糊基类全部内容,希望文章能够帮你解决c – 多重继承模糊基类所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。