jww
jww

Reputation: 102346

How to avoid name hiding warning under Visual Studio?

I have a base class:

#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();
    }
};

And a derived class:

class NO_VTABLE Bar : public Foo
{
public:

    virtual bool TestSomething() const {
        // Do the test, return the result...
    }
};

Under GCC, the program compiles cleanly with -Wall -Woverloaded-virtual. Under Visual Studio, I get a dirty compile. TestSomething from above is Available shown below.

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'

Removing NO_VTABLE makes no difference. The warning persists.

All the TestSomething are public and virtual in both the base and derived classes, so its not clear to me what is hidden from the caller.

I'm working through testing under Visual Studio, and I've encountered it on both Visual Studio 2005, 2008 and 2010. I still have other VS's to test, but at this point, I know its not a one-off.

I prefer not to turn off the warning because the file base.h is large with lots of classes, and it might encounter other problems in the future.

What does Visual Studio claim is hidden from the caller? What is the source of the warning under Visual Studio, and how do I clear it?

Upvotes: 1

Views: 1063

Answers (1)

1201ProgramAlarm
1201ProgramAlarm

Reputation: 32717

If you look up error C4266 you'll find that it says A derived class did not override all overloads of a virtual function. So for this compiler you'll need to override all of the overloads for the unsigned int & variant to be visible.

I haven't looked up in the language spec to see if this is conforming or not.

Upvotes: 2

Related Questions