i started reading about templates and i got confused on the below.
template<class T>
T max(T t1, T t2)
{
int
if (t1 > t2)
return t1;
return t2;
}
int main(){
std::cout<<max<int>(120,14.55);
return 0;
}
o/p is 120 .But when i compiled the above i got the below warning.
warning:passing double for argument 2 to T max(T, T) [with T = int]. why this warning came is my question since i have already instantiated for T max(int t1,double t2).
Because as per my understanding here if i explicitly mention only one data type(here int),other would be deducted from the argument type(14.55) by the compiler.That means T max(T t1, T t2) instantiates T max(int t1,double t2)in this case.I read this concept from some template documents in internet.
Please clear my doubts.else i cant proceed further