Example that fails to compile:
class A{
public:
int f(int a) {return a;}
};
class B: public A {
public:
int f(int a, int b) {return a + b;}
};
int calculation(int num) {
B b;
return b.f(num);
}
At the call site b.f(num), gcc gives the following error message:
error: no matching function for call to
B::f(int&)
The base class has a viable candidate, but for some reason the compiler wouldn't consider it.
If I re-write the call as b.A::f(num), then it works fine. I don't understand why the A:: is necessary. How come A::f is not considered as a viable candidate by the overload resolution logic for the b.f?