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 的回答之外,静态还需要定义为 extern。