inheritance and hidden overloads
- by Caspin
The following code doesn't compile.
struct A {};
struct B {};
class Base
{
public:
virtual void method( A param ) { }
virtual void method( B param ) = 0;
};
class Derived : public Base
{
public:
//using Base::method;
void method( B param ) { }
};
int main()
{
Derived derived;
derived.method(A());
}
The compiler can't find the overload of method() that has an A parameter. The 'fix' is to add a using declaration in the derived class. My question is why. What is the rational for a weird language rule like this?
I verified the error in both GCC and Comeau, so I assume this isn't a compiler bug but a feature of the language. Comeau at least gives me this warning:
"ComeauTest.c", line 10: warning: overloaded virtual function "Base::method" is
only partially overridden in class "Derived"
class Derived : public Base
^