I have faced some code snippets that a class can inherited from another class via its template parameter. However, I do not understanding why I need to have the three using
line in struct D
. I try to call the say_hi()
function of d
but it states error: request for member ‘say_hi’ is ambiguous
and the error gone if I have the three using
lines. Can anyone tell me why?
struct C1 {
void say_hi(int) { puts("int hi"); }
};
struct C2 {
void say_hi(char) { puts("char hi"); }
};
struct C3 {
void say_hi(double) { puts("double hi"); }
};
template<typename T, typename U, typename V>
struct D : T, U, V {
using T::say_hi;
using U::say_hi;
using V::say_hi;
};
D<C1, C2, C3> d;