英文解釋: if you declare a method to be static in your .cc file. The reason is that static means something different inside .cc files than in class declarations It is really stupid, but the keyword static has three different meanings. In the .cc file, the static keyword means that the function isn't visible to any code outside of that particular file. This means that you shouldn't use static in a .cc file to define one-per-class methods and variables. Fortunately, you don't need it. In C++, you are not allowed to have static variables or static methods with the same name(s) as instance variables or instance methods. Therefore if you declare a variable or method as static in the class declaration, you don't need the static keyword in the definition. The compiler still knows that the variable/method is part of the class and not the instance. 翻譯: 如果在你的.cc文件,你聲明的方法是靜態的。靜態意味着的.cc文件不同於類的聲明。 但關鍵字static有三個不同的含義。 在.cc文件,靜態關鍵字意味着該功能是任何代碼該文件外部不可見的。這意味着,你不應該使用靜態的.cc文件來定義一個每類方法和變量。 在C ++中,你不能有靜態變量或靜態方法在實例聲明和實例方法中具有相同的名稱(S)。 因此,如果你在類聲明聲明一個變量或方法為靜態的,你不需要在定義static關鍵字在.cc文件。 編譯器仍然知道該變量/方法是類的一部分,而不是該實例。 錯誤的: Foo.h: class Foo { public: static int bar(); }; Foo.cc: static int Foo::bar() { // stuff } 正確的: Foo.h: class Foo { public: static int bar(); }; Foo.cc: int Foo::bar() { // stuff } 這個也是正確的: Foo.h: class Foo { public: static int bar() { // stuff }; };