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++ 警告是什么意思?


基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何在 C++ 中初始化静态常量成员? 2022-01-01