【发布时间】:2016-05-26 17:54:18
【问题描述】:
我的问题可能很愚蠢,但我遇到了以下问题。
以下代码可以正常工作。我有全局或本地列表,可以正确实例化和推送值。
class THistory
{
public:
UInt32 index;
UInt32 navToID;
};
//Works Fine
class ML{
public:
static THistory *hist2;
};
main.cpp;
ML::hist2 = new THistory[HISTORY_BUFFER_SIZE];//global
std::list<THistory> histList;//global
histList.push_back(ML::hist2[0]);//inside main()
当我在类中移动列表时,问题就开始了。
//Problem
class ML{
public:
static THistory *hist2;
static std::list<THistory> histList; //replace global list and put it inside ML class as static
}
main.cpp;
ML::hist2 = new THistory[HISTORY_BUFFER_SIZE];//global as before
////// Where to initialize the list?
ML::histList.push_back(CoreML::hist2[0]); //inside main()
//LINK Error Undefined symbol
错误 LNK2001:未解析的外部符号“公共:静态类 std::list > CoreML::histList”(?histList@CoreML@@2V?$list@VTHistory@@V?$allocator@VTHistory@@@std@ @@std@@A)
我不知道如何初始化列表。任何指针都会有所帮助。
【问题讨论】:
-
您的链接器错误是针对名为
CoreML的类,但您的代码显示了一个名为ML的类。这是你写的实际代码吗?
标签: c++ list class initialization