Question: C++ Function Templates with Multiple Parameters We have successfully created a myMax() function template, which returns the larger one of its parameters. However, it only
C++
Function Templates with Multiple Parameters We have successfully created a myMax() function template, which returns the larger one of its parameters. However, it only works if the parameters have the same type. Modify the given code to enable the function to work with different parameter types (the function is called with different data types in main). The result of the myMax() function should be of the type of its first parameter.
#include
using namespace std;
//change the function
template
T myMax(T a, T b) {
return (a > b ? a : b);
}
int main () {
double x;
int y;
cin>>x>>y;
cout << myMax(x, y) << endl;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
