作用:函数名可以相同,提高复用性
满足条件:
1.同一个作用域下
2.函数名称相同
3.函数参数类型不同或者个数不同或者顺序不同
注意:函数
#include <iostream> #include <ostream> using namespace std; #include <string> void func(int &a) { cout << "func1(int &a)的调用" << endl; } void func(const int &a) { cout << "func2(int &a)的调用" << endl; } //2.函数重载碰到默认参数 void func2(int a,int b=10) { cout << "func21(int a)的调用" << endl; } void func2(int a) { cout << "func22(int a)的调用" << endl; } int main() { const int a = 10; func(a); int b = 20; func(b); func2(10,30); system("pause"); return 0; }
的返回值不满足函数重载的条件