0
這個C++代碼在編譯時生成的鏈接錯誤:C++私有靜態成員變量
// A.h
class A {
public:
static void f();
private:
static std::vector<int> v;
};
// A.cpp
void A::f() {
// this line is causing trouble
int i = v.size();
}
移動向量聲明爲cpp文件作品。不過,我想了解上述代碼中的鏈接器錯誤"Undefined symbols"
原因。上述代碼中導致鏈接器錯誤的原因是什麼?
您缺少''中A.cpp' v'的定義。 –