函数模板

#include<iostream>
using namespace std;
template<typename T>
T max(T x ,T y,T z){
    if(z>x)
    x=z;
    if(y>x)
    x=y;
    return x;
}

int main(){
    int a,b,c,m;
    cin>>a>>b>>c;
    m=max(a,b,c);
    cout<<"the max is "<<m<<endl;

    short ac,bc,cc,m2;
    cin>>ac>>bc>>cc;
    m2=max(ac,bc,cc);
    cout<<"the max is "<<m2<<endl;
    
    double ad,bd,cd,m3;
    cin>>ad>>bd>>cd;
    m3=max(ad,bd,cd);
    cout<<"the max is "<<m3<<endl;
    return 0;
}

原文地址:https://www.cnblogs.com/sanyeai/p/7811393.html