我得到這個錯誤,我不知道這意味着什麼:未定義的引用靜態變量Foo :: a?
$ mingw32-g++ Test.cpp -o Test.exe
C:\Documents and Settings\BDL\ccksiYhI.o:Test.cpp:(.text+0x11): undefined reference to 'Foo::a'
collect2: ld returned 1 exit status
這是我的代碼。
Test.cpp的
#include <vector>
#include "Test.h"
int main() {
Foo::a.clear();
return 0;
}
Test.h
#include <vector>
class Foo {
public:
static std::vector<int> a;
};
這不是我的原代碼,但我已經熬下來到這個問題。我是新來的C + +,如果任何人都可以解釋爲什麼這是錯的,我怎麼能解決它,我將不勝感激。
「你需要定義一個類的變量,如果它是靜態的」會更合適。 – Ajay