I'm trying to create a basic Python interpreter using cpp and I'm facing an unresolved external symbol problem with the container of the _variables: an unordered_map
here is the declaration:
private:
static std::unordered_map<std::string, Type*> _variables;//type is a base class for all the types of variables
and here is the relevant code using the container:
bool Parser::makeAssignment(std::string str)
{
char ch = '=';
int count = 0;
Type* newVar;
for(int i = 0; (i = str.find(ch, i)) != std::string::npos; i++)
{
count++;
}
if (count != 1)
{
return false;
}
std::string::size_type pos = str.find('=');
std::string varName = str.substr(0, pos);
std::string varVal = str.substr(pos + 1, str.size());
Helper::trim(varName);
Helper::trim(varVal);
if (!isLegalVarName(varName))
{
throw SyntaxException();
}
if (getType(varVal) != NULL)
{
newVar = getType(varVal);
}
else
{
throw SyntaxException();
}//checks if the declaration written is valid
auto it = _variables.find(varName);
if (it != _variables.end())
{
it->second = newVar;
}
else
{
_variables.insert({ varName, newVar });
}
return true;
}
Type* Parser::getVariableValue(std::string str)
{
auto it = _variables.find(str);
if (it != _variables.end())
{
return it->second;
}
return NULL;
}
void Parser::cleanMemory()
{
_variables.clear();
}
I would also appreciate an explanation for this problem in general (LNK2001) because I have encountered it several times before.