1、引用作为重载条件。
2、函数重载碰到函数默认参数。
#include <iostream>
using namespace std;
/*
函数重载注意事项。
1、引用作为重载条件。
2、函数重载碰到函数默认参数了。
*/
//1、引用作为重载条件。
void func(int &a)
{
cout << "void func(int &a)" << endl;
}
void func(const int &a) //常量引用
{
cout << "void func(const int &a)" << endl;
}
//2. 函数重载碰到函数默认参数了。
void func2(int a)
{
cout << "void func2(int a)" << endl;
}
void func2(int a,int b = 10)
{
cout << "void func2(int a,int b = 10)" << endl;
}
int main(int argc,const char *argv[])
{
//int a = 10;
//func(a); //调用第一个
//func(10); //调用第二个
//func2(10); //出现二义性 两种情况都可以调用,不知道调用哪个
//func2(10,10); //调用第二个
return 0;
}