C4250 VC++ 警告是什么意思? [英] What does C4250 VC++ warning mean?

查看:17
本文介绍了C4250 VC++ 警告是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C4250 Visual C+ 警告是什么意思在实际方面?我已阅读链接的 MSDN 页面,但我仍然不明白问题出在哪里.

What does C4250 Visual C+ warning mean in practical terms? I've read the linked MSDN page, but I still don't get what the problem is.

编译器会警告我什么,如果我忽略警告会出现什么问题?

What does the compiler warn me about and what problems could arise if I ignore the warning?

推荐答案

警告指出如果任何 weak 类操作依赖于 vbc 实现的虚拟操作在 dominant 中,那么这些操作可能会由于它们捆绑在菱形继承层次结构中而改变行为.

The warning is pointing out that if any weak class operations depend on vbc virtual operations that are implemented in dominant, then those operations might change behavior due to the fact that they are bundled in a diamond inheritance hierarchy.

struct base {
   virtual int number() { return 0; } 
};
struct weak : public virtual base {
   void print() { // seems to only depend on base, but depends on dominant
      std::cout << number() << std::endl;
   }
};
struct dominant : public virtual base {
   int number() { return 5; }
};
struct derived : public weak, public dominant {}

int main() {
   weak w; w.print();    // 0
   derived d; d.print(); // 5
}

这是标准指定的行为,但有时程序员可能会感到惊讶,weak::print 操作行为已经改变不是因为上面或下面的重写方法层次结构,但由继承层次结构中的同级类调用,当从 derived 调用时.请注意,从 derived 的角度来看,它是完全合理的,它调用的操作依赖于在 dominant 中实现的虚方法.

That is the behavior that the standard specifies, but it might be surprising for the programmer at times, the weak::print operation behavior has changed not because of an overridden method above or below in the hierarchy, but by a sibling class in the inheritance hierarchy, when called from derived. Note that it makes perfect sense from the derived point of view, it is calling an operation that depends on a virtual method implemented in dominant.

这篇关于C4250 VC++ 警告是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆