在 C++ 中无法重载的函数
在 C++ 中,我们可以重载函数。但有时不会进行重载。在本节中,我们将看到在哪些不同情况下,我们无法重载函数。
当函数签名相同,只有返回值类型不同,那么我们无法重载函数。
int my_func() {
return 5;
}
char my_func() {
return 'd';
}当成员函数在类中具有相同的名称和相同参数列表时,它们无法重载。
class My_Class{
static void func(int x) {
//Something
}
void func(int x) {
//something
}
};当参数声明仅在指针 * 和数组 [] 中不同时,它们相同。
int my_func(int *arr) {
//Do something
}
int my_func(int arr[]) {
//do something
}当参数声明仅在常数或 volatile 限定符的存在中不同时,它们相同。
int my_func(int x) {
//Do something
}
int my_func(const int x) {
//do something
}当参数声明仅在它们的默认参数中不同且相等时。
int my_func(int a, int b) {
//Do something
}
int my_func(int a, int b = 50) {
//do something
}
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP