这最好由代码本身来解释。我想用 QList<MyStruct>
作为静态成员,但出现链接器错误 2001 ( LNK2001
)。代码在文件中的顺序相同 MyClass.h
struct MyStruct{
double x;
...
};
typedef QList<MyStruct> MyStructList;
class MyClass
{
....
private:
static MyStructList _myValues; // does not work => LNK2001
MyStructList _myValues; // Test 1 OK
static QList<int> _myValues; // Test 2 OK
有什么提示吗? Eran 的回答(见下面的评论)是正确的提示。已解决
LNK2001:
error: LNK2001: unresolved external symbol "private: static class QList<struct>
最佳答案
又一个被遗忘的静态成员定义的例子……MyStructList MyClass::_myValues
应该放在项目的一个 .cpp 文件中。
关于c++ - 初始化 QList<MyStruct> 作为静态类成员给出 LNK2001 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11441396/