在C ++中不能重载的函数
在C++中,我们可以重载函数。但是有时过载不会完成。在本节中,我们将看到在哪些情况下无法重载函数。
当函数签名相同时,仅返回类型不同,那么我们就不能重载该函数。
int my_func() {
return 5;
}
char my_func() {
return 'd';
}当成员函数在类中具有相同的名称和相同的参数列表时,则不能重载它们。
class My_Class{
static void func(int x) {
//东西
}
void func(int x) {
//东西
}
};参数声明的区别仅在于指针*和数组[]相同。
int my_func(int *arr) {
//Do 东西
}
int my_func(int arr[]) {
//do 东西
}当参数声明时,仅在存在常量或易变限定符时才有所不同。
int my_func(int x) {
//Do 东西
}
int my_func(const int x) {
//do 东西
}当参数声明时,仅在默认参数方面有所不同是等效的。
int my_func(int a, int b) {
//Do 东西
}
int my_func(int a, int b = 50) {
//do 东西
}热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短