我有一個基類:如何避免在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