inheritance and hidden overloads
        Posted  
        
            by Caspin
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Caspin
        
        
        
        Published on 2010-04-07T20:44:34Z
        Indexed on 
            2010/04/07
            20:53 UTC
        
        
        Read the original article
        Hit count: 361
        
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
        ^
© Stack Overflow or respective owner