在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 东西
}