struct A {
void f(int x) {}
};
struct B {
template<typename T> void f(T x) {}
};
struct C : public A, public B {};
struct D {
void f(int x){}
template<typename T> void f(T x) {}
};
int main(int argc, char **argv) {
C c;
c.f<int>(3);
D d;
d.f<int>(3);
}
What is the reason for which calling d.f is fine, but c.f gives
error: request for member ‘f’ is ambiguous
error: candidates are: template<class T> void B::f(T)
error: void A::f(int)
The first part is due to member name lookup, that’s why it fails.
I would refer you to:
10.2/2 Member name lookupNow, for the matter with template functions.
As per
13.3.1/7 Candidate functions and argument listAnd if you continue reading
13.3.3/1 Best viable functionF1 is considered to be a better function, if:
That’s why the following snippet compiles and runs the non-template function without error: