为什么在C 中不能超载类的静态成员

Why static member of class can not be overloaded in c++?

本文关键字:静态成员 超载 不能 为什么      更新时间:2023-10-16
#include<iostream>
 class Test {
   static void fun() {}
   void fun() {} // compiler error
};
int main()
{
   getchar();
   return 0;
}

输出:

| 4 |错误:‘void test :: fun()'不能超载|

不可能直接禁止它。

引用C++14标准文档,第§13.1章,"超载声明"

  1. 某些功能声明不能超载

    • 函数声明仅在返回类型中有所不同。

    • 具有相同名称的成员函数声明,如果其中任何一个是static成员函数声明,则不能超载相同的参数类型。[....]