我有一个基类:如何避免在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下警告的来源是什么?如何清除它?
作为一种解决方法,您可以在导致问题的行周围推送和弹出警告 - 毕竟这些都是非常旧的编译器。 – Rostislav
@Rostislav - 谢谢。编译器版本与它有什么关系?据我所知,都是C++ 03,它符合项目的要求。 – jww