函数重载
- 函数在同一个作用域。
- 函数名相同。
- 函数参数不同,或参数顺序不同。
比如:
void test(int a)
{
cout << "1" << endl;
}
void test(double a)
{
cout << "2" << endl;
}
特殊情况:当重载函数有默认参数时
void test(int a,int b = 10)
{
cout << "1" << endl;
}
void test(int a)
{
cout << "2" << endl;
}
int main()
{
int a = 1;
test(a);//程序会报错,因为默认参数的问题,使函数重载出现二义性。
}