C++函数重载:
函数重载:是函数的一种特殊情况,C++允许在同一作用域中声明几个功能类似的同名函数,这些同名函数的形 参列表(参数个数 或 类型 或 顺序)必须不同,常用来处理实现功能类似数据类型不同的问题
#include <iostream>
#include <stdlib.h>
using namespace std;
//全缺省参数
void TestFunc1(int a = 10,int b=20,int c=30)
//10,20,30为函数的缺省参数,当函数没有传参数时 10位默认函数参数
{
cout << a << endl;
cout << b << endl;
cout << c << endl;
}
//半缺省参数
void TestFunc2(int a = 10, int b = 20, int c = 30)
{
cout << a << endl;
cout << b << endl;
cout << c << endl;
}
int Add(int a, int b) {
return a + b;
}
double Add(double a, double b) {
return a + b;
}
int Add(int a, double b) {
return a+b;
}
int Add(double a, int b) {
return a+b;
}
int main() {
TestFunc1(10);
TestFunc1(20);
TestFunc1(30);
TestFunc2(10);
system("pause");
return 0;
}