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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!