函数的重载

#include <iostream>
using namespace std;

int max(int x ,int y,int z);
double max(double x ,double y,double z);
long max(long x ,long y,long z);

int main(){
    
    int a,b,c,m;
    cout<<"请你输入三个整型的数字:"<<endl;
    cin>>a>>b>>c;
    m=max(a,b,c);
    cout<<"The max of a b and c is:"<<m<<endl;
    
    double ad,bd,cd,md;
    cout<<"请你输入三个小数类型的数字:"<<endl;
    cin>>ad>>bd>>cd;
    md=max(ad,bd,cd);
    cout<<"The max of a b and c is:"<<md<<endl;
    
    long al,bl,cl,ml;
    cout<<"请你输入三个长整型的数字:"<<endl;
    cin>>al>>bl>>cl;
    ml=max(al,bl,cl);
    cout<<"The max of a b and c is:"<<ml<<endl;
    return 0;
} 
inline int max(int x ,int y,int z){
    if(z>x)
    x=z;
    if(y>x)
    x=y;
    return x;
}
inline double max(double x ,double y,double z){
    if(z>x)
    x=z;
    if(y>x)
    x=y;
    return x;
}
inline long max(long x ,long y,long z){
    if(z>x)
    x=z;
    if(y>x)
    x=y;
    return x;
}

posted @ 2017-11-09 21:43  羿龙  阅读(124)  评论(0编辑  收藏  举报