可能重複:
C++: undefined reference to static class member未定義引用靜態變量
我使用MinGW的。爲什麼靜態變量不工作
[Linker error] undefined reference to `A::i'
#include <windows.h>
class A {
public:
static int i;
static int init(){
i = 1;
}
};
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil){
A::i = 0;
A::init();
return 0;
}
添加一個定義,你應該改變init'的'返回無效,或返回的東西 –
這個問題已經被問過無數次前:http://stackoverflow.com/questions/272900/c -undefined-reference-to-static-class-member http://stackoverflow.com/questions/12117859/c-undefined-reference-to-static-variable http://stackoverflow.com/questions/3672088/undefined-reference -error-due-of-use-of-static-variables http://stackoverflow.com/questions/7787059/g-undefined-reference-static-member-variable還有更多 –