Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
手伝ってくれますか?次のコード:
class MT { public: static int ms_number; }; int MT::ms_number;
収量:
Error 8 error LNK2005: "public: static int MT::ms_number" (?ms_number@MT@@2HA) already defined in ProjName.obj
なんで?
この行を移動する必要があります:
int MT::ms_number;
.h ファイルから単一の .cpp ファイルに変換します。
R Samuel Klatchko の回答に加えて、 static を extern として定義する必要があります。