Write a template function in C that returns a greater number
Write a template function in C++ that returns a greater number of the two integer numbers.
Solution
The template function in C++ with sample program is given below. Comments are also added. Have a look.
#include <iostream>
 using namespace std;
// template function to return greater number of the two integers
 template <typename T>
 T maxInteger (T num1, T num2)
 {
     return num1 < num2 ? num2 : num1; //condition operator is used
 }
int main()
 {
    cout<<maxInteger<int>(10, 15);         // method call to template function
 }
Output: 15

