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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started