Possible Duplicate:
overloaded functions are hidden in derived class
I have Class A and Class B (subclass of A)
Class A has function
virtual void foo(int, int);
virtual void foo(int, int, int);
When I try to do
Class B with function
virtual void foo(int, int);
When I try to call foo(int, int, int) with the class the compiler won’t let me because it says
no matching function for foo(int,int,int)
candidate is foo(int,int);
The reason why has to do with the way C++ does name lookup and overload resolution. C++ will start at the expression type and lookup upwards until it finds a member matching the specified name. It will then only consider overloads of the member with that name in the discovered type. Hence in this scenario it only considers
foomethods declared inBand hence fails to find the overload.The easiest remedy is to add
using A::foointoclass Bto force the compiler to consider those overloads as well.