• 引用作为重载条件
  • 函数重载碰到函数默认参数 ```cpp

    include

using namespace std;

// 函数重载的注意事项 // 1.引用作为重载条件 void func(int &a) { // int &a = 10; 不合法 cout << “func(int &a)” << endl; } void func(const int& a) { // const int &a = 10; 合法 cout << “func(const int &a)” << endl; } // 2.函数重载碰到默认参数 void func2(int a, int b = 10) { cout << “func2(int a, int b = 10)的调用” << endl; } void func2(int a) { cout << “func2(int a)的调用” << endl; } int main() { //int a = 10; //func(a);

  1. func(10);
  2. //func2(20); // 当函数重载碰到默认参数,出现二义性, 报错
  3. func2(10, 20);
  4. system("pause");
  5. return 0;

} ```