Suppose I have a simple program to find the largest of two numbers of different datatypes and return the largest.I'm implementing it as a template to support generic datatypes
template<class T,class U>
T max(T t,U u)
return (t>u?t:u);
int main()
{
int x=70;
float y=100.5;
max(x,y);
return 0
}
Here the second generic datatype is the largest , but since return type is given as 1st type T(integer in this case ) the result gets truncated.Is there any other way to make the system identify and pass the return type also ? So that return type can also change dynamically depending on input. Please help me