C++ “fatal error LNK1120” unresolved static class members

那年仲夏 提交于 2019-11-28 14:19:58

You need to create instances of your static members in the FD.cpp file:

//FD.cpp
#include "FD.h"
#include "Mappings.h"
#include "Utils.h"
#include <vector>
#include <string>
#include <iostream>
#include <unordered_map>

using namespace std;

unordered_map<string,string> FD::FIXFieldNoDict = Mappings::createFIXFieldNoDict();
unordered_map<string,string> FD::FixValueMappingsDict = Mappings::getFIXValuesDict();


FD::FD(){
}

Note that you shouldn't initialize them in the FD constructor, as you can use static members before construction of any object (and you need to initialize them once and not every time when some object is constructed).

You should implement this two members in FD.cpp file:

static unordered_map<string,string> FIXFieldNoDict;
static unordered_map<string,string> FixValueMappingsDict;

like that:

unordered_map<string,string> FD::FIXFieldNoDict;
unordered_map<string,string> FD::FixValueMappingsDict;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!