函数模板

Posted on 2017-12-18 15:53  dragonliu欧美  阅读(92)  评论(0编辑  收藏  举报
 1 #include<iostream>
 2 using namespace std;
 3 template<typename T>
 4 T max(T x ,T y,T z){
 5     if(z>x)
 6     x=z;
 7     if(y>x)
 8     x=y;
 9     return x;
10 }
11 
12 int main(){
13     int a,b,c,m;
14     cin>>a>>b>>c;
15     m=max(a,b,c);
16     cout<<"the max is "<<m<<endl;
17 
18     short ac,bc,cc,m2;
19     cin>>ac>>bc>>cc;
20     m2=max(ac,bc,cc);
21     cout<<"the max is "<<m2<<endl;
22     
23     double ad,bd,cd,m3;
24     cin>>ad>>bd>>cd;
25     m3=max(ad,bd,cd);
26     cout<<"the max is "<<m3<<endl;
27     return 0;
28 }