#include<iostream>
#include<stdlib.h>
#include<iomanip>
using namespace std;
template<class T>
T add(T a,T b)
{
return a+b;
}
template<class T>
T multiply(T m,T n)
{
return m*n;
}
int main()
{
int x=4;int y=5;int z;
float i=4.5,j=3;float k;
k=add(i,j);
z=add(x,y);
cout<<"4+5="<<z<<endl;
cout<<"4.5+3="<<k<<endl;
cout<<"4*5="<<multiply(x,y)<<endl;
cout<<"4.5*3="<<multiply(i,j)<<endl;
system("pause");
return 0;
}
调试结果截图: