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

问题描述

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 dominant 中实现的 vbc 虚拟操作,那么这些操作可能会由于它们捆绑在钻石继承层次中。

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 操作行为已经改变不是因为在层次结构中上面或下面的重写方法,而是由继承中的同级类当从派生调用时。注意,从派生的观点来看,它是非常有意义的,它调用一个依赖于在中实现的虚方法的操作

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 ++警告是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 03:48