Say I have a static map variable in a class. Where do I put the code to fill the map so all objects of the class type can use it?
Code:
class Round
{
private:
static std::map<const std::string, int> mapStringToInt;
.....
public:
Round();
};
Here's the code I use to fill the map when it's not a static member variable:
Code:
const std::string IntToStr(int x)
{
if(x == 0)
return "w";
else
return "b";
}
std::string referenceString, A, B, C, D;
int a, b, c, d, num = 1;
//generate referenceString first
for(a = 0; a < 2; ++a)
{
A = intToStr(a);
for(b = 0; b < 2; ++b)
{
B = intToStr(b);
for(c = 0; c < 2; ++c)
{
C = intToStr(c);
for(d = 0; d < 2; ++C)
{
D = intToStr(d);
referenceString = A + B + C + D;
//then map referenceString to num
mapStringToInt[referenceString] = num++;
}
}
}
}
Also, is it possible to make the map unchangeable once it's created? Maybe something like this:
const static std::map<const std::string, int> mapStringToInt;
Thanks.