2016-11-23 91 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. [....]

相關問題