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++ 警告是什么意思?
基础教程推荐
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 从 std::cin 读取密码 2021-01-01