我的項目僅由兩個源文件:爲什麼「extern const int n;」不按預期工作?
a.cpp:
const int n = 8;
b.cpp:
extern const int n;
int main()
{
// error LNK2001: unresolved external symbol "int const n" ([email protected]@3HB)
int m = n;
}
我知道有幾個方法,使其工作;然而,我只是想知道爲什麼它不起作用?
嘗試將'a.cpp'改爲'extern const int n = 8;'AFAIK'const'意味着'static',儘管我不太清楚。 – Pubby 2013-02-15 12:26:22
a.cpp是否需要使用extern關鍵字查看n的decleration? – 2013-02-15 12:28:43
你沒告訴我們你的鏈接和如何... – PlasmaHH 2013-02-15 12:28:58