Learning  C++
Home
Tutorials
C++  Programs
Contact  us
Sitemap
// Program to illustrate function templates


#include<iostream.h>

template <class T>
T max(T a, T b)
{
     return (a>b)?a:b;
}


void main()
{
     int a=55,b=33;
     cout<<"\n Maximum of "<<a<<" and "<<b<<"is :"<<max(a,b);
     float c=1.5,d=3.4;
     cout<<"\n Maximum of"<<c<<" and "<<d<<"is :"<<max(c,d);
}



Test data

Output
Maximum of  55  and  33 is : 55
Maximum of  1.5  and 3.4 is : 3.4