To compute the maximum of two values, I have a specialized function and a generic templated version of the same function. During testing, I am passing a char and a double as argument to the function and as there is no function that matches the type of arguments, I am expecting the compiler to throw error. But it is not the case
#include <iostream>
using namespace std;
int max(int a, int b) {
cout << "resolved to max() specialized\n";
return a > b ? a : b;
}
template<typename T>
T max(T a, T b) {
cout << "resolved to max() templated\n";
return a > b ? a : b;
}
int main() {
cout << max('a',2.1) << "\n"; // why specialized max(int,int) is invoked ?
return 0;
}