Question: C++ Function Templates You need to write a function, which returns the maximum of its two parameters, and it should work for different data types

C++

Function Templates

You need to write a function, which returns the maximum of its two parameters, and it should work for different data types (integers, doubles, etc.) Create a function template called myMax(), which takes two parameters and returns the larger one, so that the code in main works as expected. Sample Input 4.2 8.1 Sample Output 8.1

Remember, the syntax for declaring a template function is template

#include

using namespace std;

//your code goes here

int main () {

double x, y;

cin>>x>>y;

int a, b;

cin>>a>>b;

cout << myMax(x, y) << endl;

cout << myMax(a, b) << 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!