1.C++允许多个函数拥有相同的名字,只要它们的参数列表不同就可以。这就是函数的重载(Function Overloading)。借助重载,一个函数名可以有多种用途。
2.实例
//参数类型不同
int max(int a,int b,int c);
double max(double a,double b,double c);
//参数个数不同
int max(int a,int b,int c);
int max(int a,int b);
//参数顺序不同
int max(int a,double b);
int max(double a,int b);
3.总结
函数的重载的规则:
函数名称必须相同。
参数列表必须不同(个数不同、或类型不同、参数排列顺序不同等)。
函数的返回类型可以相同也可以不相同。