如何在Visual Studio下避免名称隐藏警告?

时间:2015-10-17 23:27:18

标签: c++ visual-studio compiler-warnings overloading

我有一个基类:

#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下警告的来源是什么,如何清除它?

1 个答案:

答案 0 :(得分:1)

如果您查找错误C4266,您会发现它显示A derived class did not override all overloads of a virtual function.因此,对于此编译器,您需要覆盖unsigned int &变体的所有重载才能显示。

我没有在语言规范中查看是否符合要求。