模板的概念可以百度在此不作赘述
下面是函数模板的简单应用举例:
//模板的练习
#include<iostream>
#include<string>
using namespace std;
template<class T>
void SSwap(T &x,T &y)
{
T t;
t=x;
x=y;
y=t;
cout<<x<<" "<<y<<endl;
}
int main()
{
int a=3,b=4;
double c=7,d=8;
char e='h',f='i';
cout<<"befor exchange(交换前):"<<endl;
cout<<a<<" "<<b<<endl;
cout<<c<<" "<<d<<endl;
cout<<e<<" "<<f<<endl;
cout<<"after exchange(交换后):"<<endl;
SSwap(a,b);
SSwap(c,d);
SSwap(e,f);
return 0;
}