有以下幾個文件:global.cpp:inttest=5;global.hexterninttest;extern.hinclude"global.h"voidtest_fun();extern.cpp#include#include"extern.h"voidtest_fun(){printf("%d\n",test);}main.cpp#include"extern.h"intmain(intargc,char*argv[]){test_fun();return0;}上面的代碼運行起來是沒有問題的,但是,當我把global.cpp和global.h里面的int改成constint類型之后就會報下面的錯誤:errorLNK2001:unresolvedexternalsymbol"intconsttest"請問constint和int在extern下作用的區別是什么,為什么第二種情況會報錯?更新:這個問題只會出現在C++里面,在C里面能正確的運行。
extern int 和extern const int的區別?
江戶川亂折騰
2019-04-09 20:23:28