Thursday, 21 September 2017

Function template to check max numebr in C++

 Function template demo to check max number in c++ 
#include "iostream"
using namespace std;

template <typename T>
T getMax(T x, T y){
 return (x>y?x:y);

int main(){
 cout<<"Max No: "<< getMax <int> (4,5)<<endl;
 return 0;
[pavan@localhost Template]$ g++ FunctionTemplate.cpp
[pavan@localhost Template]$ ./a.out 
Max No: 5
[pavan@localhost Template]$ 


No comments: