In order for the compiler to deduce the template parameter A
from the arguments passed to the function template, both arguments, a
and b
must have the same type.
Your arguments are of type int
and double
, and so the compiler can't deduce what type it should actually use for A
. Should A
be int
or should it be double
?
You can fix this by making both arguments have the same type:
printMax(1.0, 14.45);
or by explicitly specifying the template parameter:
printMax<double>(1, 14.45);
The reason that the call to the non-template function can be called is that the compiler does not need to deduce the type of the parameters: it knows the type of the parameters because you said what they were in the function declaration:
void printMaxInts(int a, int b)
Both a
and b
are of type int
. When you pass a double
as an argument to this function, the double -> int
standard conversion is performed on the argument and the function is called with the resulting int
.