What does C4250 VC++ warning mean?(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++ 警告是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C4250 VC++ 警告是什么意思?
基础教程推荐
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
