2016-11-23 62 views
-1
#include<iostream> 
class Test { 
    static void fun() {} 
    void fun() {} // compiler error 
}; 

int main() 
{ 
    getchar(); 
    return 0; 
} 

输出:为什么类的静态成员不能在C++中重载?

|4|error: ‘void Test::fun()’ cannot be overloaded|

+2

所以,开始卸下C标记...你自己的 –

+0

右C++编译器使用这一功能。我们可以称之为另一种选择。 –

回答

0

为标准直接禁止它是不可能的。

报价§13.1 C++14标准文档,章,“声明重载的”

  1. Certain function declarations cannot be overloaded

    • Function declarations that differ only in the return type cannot be overloaded.

    • Member function declarations with the same name and the same parameter types cannot be overloaded if any of them is a static member function declaration. [....]

相关问题