I declared a static unordered map in a header file as follows:
static boost::unordered_map<KeyAction, sf::Key::Code> WindowKeyMap;
in that same header file, i have a function that fills the map with some values:
static void Initialize(std::string &file)
{
WindowKeyMap[MoveLeft] = sf::Key::Code::Left;
WindowKeyMap[MoveRight] = sf::Key::Code::Right;
WindowKeyMap[MoveUp] = sf::Key::Code::Up;
WindowKeyMap[MoveDown] = sf::Key::Code::Down;
std::cout << std::endl << WindowKeyMap.size() << std::endl;
}
Later on in my program, inside a seperate class/function, i attempt to read one of the values:
std::cout << std::endl << WindowKeyMap.size() << std::endl;
auto test2 = WindowKeyMap[MoveRight];
but the map is always empty. The output to the console is always 4 from the initialize routine then 0 from the second cout. I thought static maps were persistent across the program, so I'm a little confused as to how my static map becaomes empty. Can anyone shed some light?
Thanks