歧义问题

编程入门 行业动态 更新时间:2024-10-25 12:27:06
本文介绍了歧义问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我认为编译器在这种情况下过于严格。你可以看到,没有数据成员,没有虚拟功能。 我使用的是Visual Studio 2008.编译错误只是因为Diamond模式 - 重复基类?实际上从逻辑的角度来看,应该没有歧义问题。 任何想法?

Hello everyone, I think compiler is too strict in this case. You can see, no data member, no virtual function. I am using Visual Studio 2008. The compiler error is simply because of Diamond pattern -- duplicate base class? Actually from logical point of view, there should be no ambiguity issue. Any ideas?

展开 | 选择 | Wrap | 行号 推荐答案

大家好, 我认为编译器在这种情况下过于严格。你可以看到,没有数据成员,没有虚拟功能。 我使用的是Visual Studio 2008.编译错误只是因为Diamond模式 - 重复基类?实际上从逻辑的角度来看,应该没有歧义问题。 任何想法? Hello everyone, I think compiler is too strict in this case. You can see, no data member, no virtual function. I am using Visual Studio 2008. The compiler error is simply because of Diamond pattern -- duplicate base class? Actually from logical point of view, there should be no ambiguity issue. Any ideas? 展开 | 选择 | Wrap | 行号

这是从MSDN 2003文档中获取的 This was taken from the MSDN 2003 documentation ''operator'':'来自'的模糊转换'type1''到''type2'' 没有从type1到type2的转换比任何其他转换更直接。一种可能的解决方案是定义或指定显式转换。 以下示例生成C2594: // C2594.cpp // compile with:/ c struct A {}; struct I1:A {}; struct I2:A {}; struct D:I1,I2 {}; A * f(D * p){ return(A *)(p); // C2594 //尝试以下行代替 // return reinterpret_cast< A *> (p); } ''operator'' : ambiguous conversions from ''type1'' to ''type2'' No conversion from type1 to type2 was more direct than any other. One possible solution is to define or specify an explicit conversion. The following sample generates C2594: // C2594.cpp // compile with: /c struct A{}; struct I1 : A {}; struct I2 : A {}; struct D : I1, I2 {}; A *f (D *p) { return (A*) (p); // C2594 // try the following line instead // return reinterpret_cast<A*> (p); }

这对你有用吗? 究竟是什么你还试着去做吗?我打赌你可以节省一些时间提出不同的问题,而不是试错。但那又是我学习的方式。 请记住,对象Final和函数foo()中的函数表中没有多个条目。只有一个。 对象pb指向不同的函数表,并将使用foo()的实例; 更改一些代码到这个

Does this make since to you? Just what are you trying to do anyway. I bet you could save some time asking different question rather than trial and error. But then again that is how I learned. keep in mind that there are not multiple entries in the function table for the object Final, and for the function foo(). There is only one. the object pb points to a different function table, and will use that instance of foo(); change some code to this

展开 | 选择 | Wrap | 行号

嗯.. 您继承Derived1和Derived2。 非常重要的是它们都来自Base。 所以Final Class将收到两份基础。一个来自Derived1,另一个来自Derived2。 。 Well.. You are inheriting through Derived1 and Derived2. And very imp thing is that both of them were derived from Base. So Final class will receive two copies of Base. One from Derived1 and other from Derived2. .

这不是真的; Derived1和Derived2都有foo,但是一旦他声明了函数foo()的新实例,这两个方法都会被本地定义覆盖。 取出当地的定义,看看会发生什么。 Dan -

Thats not true; Both Derived1 and Derived2 have foo that is true, but once he declared a new instance of the function foo(), both of those methods are overridden with the local definition. Take out the local definition and see what happens. Dan -

更多推荐

歧义问题

本文发布于:2023-11-07 06:45:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1565797.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:歧义

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!