Does a virtual function override a non-virtual function of the same name in a base class?

c++

Solution

The code is well-formed. `C::func` overrides `A::func`. `B::func` is an unrelated function. The spec reads (10.3/2):

If a virtual member function `vf` is declared in a class `Base` and in a class `Derived`, derived directly or indirectly from `Base`, a member function `vf` with the same name, parameter-type-list, cv-qualification, and ref-qualifier (or absence of same) as `Base::vf` is declared, then `Derived::vf` is also virtual (whether or not it is so declared) and it overrides111 `Base::vf`.

`C::func` has the same name as `A::func` and `A::func` is virtual, therefore `C::func` overrides `A::func`. `B::func` has no relation to `A::func`; I don't know that there is any language in the spec that expressly addresses that scenario.

The Visual C++ 11 Beta compiler does not emit any warnings or errors for this code.

Problem

Is the following standard conforming? Can you cite the section? ``` struct A { virtual void func() = 0; }; struct B { void func(){} }; struct C : public A, public B { virtual void func(){ B::func(); } }; ``` I'm getting a strange compiler warning in VS2010 in equivalent but more complicated code pointing to `func`'s declaration in the derived-most class: `warning C4505: unreferenced local function has been removed`. I have no idea why the compiler thinks a virtual function declared in a class is a local; however I can't repro that warning in a simpler example. Edit: I figured out a small repro case for the warning. I think I was going down the wrong path assuming it was related to function hiding. Here's the repro case: ``` template<typename T> struct C { int GetType() const; virtual int func() const; // {return 4;} // Doing this inline removes the warning <-------------- }; template<typename T> int C<T>::GetType() const { return 0; } template<> int C<int>::GetType() const { return 12; } template<typename T> int C<T>::func() const { return 3; } // Adding the following removes the warning <-------------------- // template<> // int C<int>::func() const // { // return 4; // } ``` I'm fairly sure this is just a VS2010 bug.

Original source