Expand|Select|Wrap|Line Numbers
- template<class T>
- T max(T t1, T t2)
- {
- if (t1 > t2)
- return t1;
- return t2;
- }
int main(){
std::cout<<max<int>120,14.55);//=>as per my understanding here if i explicitly mention only one data type,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.But when i compiled it i got the below warning
warning: passing double for argument 2 to T max(T, T) [with T = int].Then why this warning came is my question since i have already instantiated for T max(int t1,double t2).
also since we are using only T,if i mention max<int>,then T max(T t1, T t2) should be like this int max(int t1, int t2) na??
return 0;
}
Please clear my doubts.else i cant proceed further