如何避免Visual Studio下的名称隐藏警告
How to avoid name hiding warning under Visual Studio?
有一个基类:
#define OUT
#define NO_VTABLE __declspec(novtable)
class NO_VTABLE Foo
{
public:
virtual bool TestSomething() const = 0;
virtual bool TestSomething(OUT unsigned int& extendedInfo) const {
UNUSED(extendedInfo);
return TestSomething();
}
};
和派生类:
class NO_VTABLE Bar : public Foo
{
public:
virtual bool TestSomething() const {
// Do the test, return the result...
}
};
在GCC下,程序用-Wall -Woverloaded-virtual
编译干净。在Visual Studio下,我得到一个脏编译。上面的TestSomething
就是下面的Available
。
1> ...derived.h(78) : warning C4266: 'bool DeviceState::Available(unsigned int &) const' :
no override available for virtual member function from base 'DeviceState'; function is hidden
1> ...base.h(794) : see declaration of 'DeviceState::Available'
1> ...base.h(787) : see declaration of 'DeviceState'
去除NO_VTABLE
后没有影响。警告仍然存在。
所有的TestSomething
在基类和派生类中都是公共的和虚拟的,所以我不清楚调用者隐藏了什么。
我正在Visual Studio下进行测试,我在Visual Studio 2005、2008和2010上都遇到过这个问题。我还有其他的VS要测试,但在这一点上,我知道这不是一次性的。
我不喜欢关闭警告,因为文件base.h
很大,有很多类,将来可能会遇到其他问题。
Visual Studio声称对调用者隐藏了什么?Visual Studio下的警告来源是什么,如何清除它?
如果你查找错误C4266,你会发现它说A derived class did not override all overloads of a virtual function.
,所以对于这个编译器,你需要覆盖unsigned int &
变体可见的所有重载。
我没有在语言规范中查看这是否符合。
相关文章:
- 警告处理为错误这里有什么问题
- 使用动态分配的数组会导致代码分析发出虚假的C6386缓冲区溢出警告
- cppcheck在const std::string[]上引发警告
- GCC对可能有效的代码抛出init list生存期警告
- 如何在BST的这个简单递归实现中消除警告
- 这是我尝试让用户将值输入到数组中.然后将其隐藏为大量的星号
- 关于std::move的使用,是否有编译警告
- g++ 在某个类成员未初始化时不发出警告
- 如何处理来自核心指南检查器的关于gsl::at的静态分析警告
- 从多个模板化基类派生时出现"隐藏重载的虚函数"警告
- 如何在外部库中隐藏汇编中的警告
- libc++ 持续时间隐藏警告不正确
- 编译器不应该对派生类中隐藏的基本结构的成员变量发出警告吗?
- 如何在 ubuntu 12.10 中隐藏 g++ c++11 编译警告
- 不应该有虚拟功能隐藏的警告吗?
- 如何避免Visual Studio下的名称隐藏警告
- 对于隐藏具有类似原型的非虚拟方法没有警告(g++ 4.4)
- 使用 g++ 编译C++时,"隐藏构造函数"警告是什么意思?
- 如何隐藏链接器警告
- 使用makefile隐藏clang警告