0
我有一個簡單的.h文件中是這樣的:爲什麼鏈接器在這裏不會產生多個定義錯誤?
//test.h
int x = 12;
如果我包括在該文件中,例如,main.cpp
和functions.cpp
鏈接器將產生這個錯誤是合理的:
error LNK2005: "int x" ([email protected]@3HA) already defined in functions.obj
但是,當我更改變量定義:
//test.h
const int x = 12;
鏈接器錯誤消失。辦法?
等等,這不可能是正確的 – 2013-02-27 18:53:33
@MooingDuck:那可能是,也是,是的。 – 2013-02-27 18:55:39
@MooingDuck對不起,錯誤的部分。 §7.1.1/ 7。 – 2013-02-27 18:55:56