内联函数

#include<bits/stdc++.h>
using namespace std;
inline int Max(int,int);
int main(void)
{
int a,b,c,d,e,f;
scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);//1 2 3 4 5 6
int k=Max(a,b);
//编译器会将这句指令编译成如下
/*if(a>b){
tmp=a
}else{
tmp=b;
}
k=tmp;*/
int m=Max(c,d);
int n=Max(e,f);
cout<<k<<endl;//2
cout<<m<<endl;//4
cout<<n<<endl;//6
return 0;
}
inline int Max(int x,int y)
{
return x>y?x:y;
}
重载函数

#include<bits/stdc++.h>
using namespace std;
double Max(double,double);
int Max(int,int);
int main(void)
{
double a,b;
int c,d;
scanf("%lf %lf %d %d",&a,&b,&c,&d);//3.5 2.4 3 6
double k=Max(a,b);//Correct
int m=Max(c,d);//Correct
int n=Max(a,c);//Error:call of overloaded 'Max(double&, int&)' is ambiguous
cout<<k<<endl;//3.5
cout<<m<<endl;//6
return 0;
}
double Max(double m,double n)
{
return m>n?m:n;
}
int Max(int x,int y)
{
return x>y?x:y;
}
函数的缺省参数

