#include "iostream"
using namespace std;
template <typename T>//
用函数模板写的,呵呵,感觉重载代码量有点多,本人能力有限,你看看对你有用吗。
T max(T a,T b)
{
if(a<b) a=b;
return a;
}
template <typename T>
T max(T a,T b,T c)
{
if(a<b) a=b;
if(a<c) a=c;
return a;
}
int main()
{
int i_1,i_2,i_3;
float f_1,f_2,f_3;
double d_1,d_2,d_3;
int i_a,i_b;
float f_a,f_b;
double d_a,d_b;
cout<<"Please input two int:"<<endl;
cin>>i_a>>i_b;
cout<<"the max of two int is:"<<max(i_a,i_b)<<endl;
cout<<"Please input two float:"<<endl;
cin>>f_a>>f_b;
cout<<"the max of two float is:"<<max(f_a,f_b)<<endl;
cout<<"Please input two double:"<<endl;
cin>>d_a>>d_b;
cout<<"the max of two double is:"<<max(d_a,d_b)<<endl;
cout<<"Please input three int:"<<endl;
cin>>i_1>>i_2>>i_3;
cout<<"the max of three int is:"<<max(i_1,i_2,i_3)<<endl;
cout<<"Please input three float:"<<endl;
cin>>f_1>>f_2>>f_3;
cout<<"the max of three float is:"<<max(f_1,f_2,f_3)<<endl;
cout<<"Please input three double:"<<endl;
cin>>d_1>>d_2>>d_3;
cout<<"the max of three double is:"<<max(d_1,d_2,d_3)<<endl;
return 0;
}