struct A {
void f(int x) {}
};
struct B {
template void f(T x) {}
};
struct C : public A, public B {};
struct D {
void f(int x){}
te
Consider this simpler example:
struct A{
void f(int x){}
};
struct B{
void f(float t){}
};
struct C:public A,public B{
};
struct D{
void f(float n){}
void f(int n){}
};
int main(){
C c;
c.f(3);
D d;
d.f(3);
}
In this example, same as yours, D
compiles but C
does not.
If a class is a derived one, member lookup mechanism behaves different. It checks each base class and merges them: In the case of C
; Each base class matches the lookup ( A::f(int) and B::f(float) ). Upon merging them C
decides they are ambiguous.
For the case class D
: int
version is selected instead of float
because parameter is an integer.