I created map that connects enum with strings in order to have easier times doing current project. Code looks like this:
struct responseMap : public std::map < std::string, CitizenType > {
responseMap() {
this->operator[]("slave") = CitizenType::slave;
this->operator[]("trader") = CitizenType::trader;
this->operator[]("priest") = CitizenType::priest;
this->operator[]("scholar") = CitizenType::scholar;
this->operator[]("soldier") = CitizenType::soldier;
this->operator[]("archer") = CitizenType::archer;
this->operator[]("swordsman") = CitizenType::swordsman;
this->operator[]("emperor") = CitizenType::emperor;
}
};
My enum is just these types, described in map. Everything works fine exept it doesn't count "slave" as a member of map. For instance if I write down the following code:
responseMap myMap;
std::cout<<myMap["slave"]<<" "<<myMap["trader"];
it would produce the following line: 0 1
My question is why this is happening as I am describing them the same way?
Edit: I am trying with normal map like this:
std::map<std::string, CitizenType> otherMap = {
{ "slave", CitizenType::slave },
{ "trader", CitizenType::trader },
{ "priest", CitizenType::priest },
{ "scholar", CitizenType::scholar },
{ "soldier", CitizenType::soldier },
{ "archer", CitizenType::archer },
{ "swordsman", CitizenType::swordsman },
{ "emperor", CitizenType::emperor },
};
And it still outputs the same values.
CitizenType::slaveis 0, and the numeric value ofCitizenType::traderis 1. Which is what you see printed. What again seems to be the problem?CitizenType::[insert word here]is a member of the current enum