规则
- 函数名相同
- 参数个数不同,参数类型不同,参数顺序不同(参数类型不相同的前提下)
void display(int a) {
cout << "display(int a)" << endl;
}
void display(int a, int b) {
cout << "display(int a, int b)" << endl;
}
void display(int a, double b) {
cout << "display(int a, double b)" << endl;
}
void display(double a, int b) {
cout << "display(double a, int b)" << endl;
}
main
函数方法调用
display(3);
display(2, 3);
display(2.0f, 3);
display(2, 3.0f);
输出结果:
display(int a)
display(int a, int b)
display(double a, int b)
display(int a, double b)
注意
- 返回值类型与函数重载无关
- 调用函数时,实参的隐式类型转换可能会产生二义性
本质
- 采用了
name mangling
或者叫name decoration
技术
网友评论