为什么在C 中不能超载类的静态成员
Why static member of class can not be overloaded in c++?
#include<iostream>
class Test {
static void fun() {}
void fun() {} // compiler error
};
int main()
{
getchar();
return 0;
}
输出:
| 4 |错误:‘void test :: fun()'不能超载|
不可能直接禁止它。
引用C++14
标准文档,第§13.1章,"超载声明"
某些功能声明不能超载
函数声明仅在返回类型中有所不同。
具有相同名称的成员函数声明,如果其中任何一个是
static
成员函数声明,则不能超载相同的参数类型。[....]
相关文章:
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 如何在C++中使用非静态成员函数作为回调函数
- (C++)为什么静态成员可以在初始化之前使用
- 类的全局对象和静态成员
- 在作为静态成员包含在另一个类中的类的构造函数中使用 cout
- 模板化类中静态成员的延迟初始化
- 使用静态成员声明类时遇到问题
- C++:是否可以使用非静态成员变量模板?
- 静态成员函数使用相同的名称时出现模板类型名称错误
- 如何在复杂继承中访问静态成员变量
- 在 nullptr 上调用无状态类的非静态成员函数是否合法?
- 如何在友元函数中使用静态成员而不添加前缀 [类名]::
- C++构造函数和静态成员
- 为什么传递非静态成员函数会导致编译错误?
- 非静态成员失败的线程调用函数
- 静态成员变量不会由 gettext 转换
- decltype:使用指针访问类的静态成员
- 处理类内的回调时,必须调用对非静态成员函数的引用
- 非静态成员函数的 decltype 格式不正确吗?
- 为什么在C 中不能超载类的静态成员