Thursday, 21 September 2017

Function template with two generic types in C++

/*
 Function template with two generic types
*/

#include "iostream"
using namespace std;

template <class T1, class T2>
void display(T1 xx, T2 yy){
 cout<<endl<<xx<<" "<<yy;
}

int main(){
 display("Hello guys", 10);
 display(20.100, "Thanks");
 cout<<endl;
 return 0;
}

/*
 OUTPUT

[pavan@localhost Template]$ g++ TempDemo2.cpp
[pavan@localhost Template]$ ./a.out 

Hello guys 10
20.1 Thanks
[pavan@localhost Template]$ 
*/

No comments: