I have a global variable initialized as such:
main.cpp
map<const string, vector<string>> cmdOutputMap({ {cmd1, output1},
{cmd2, output2},
{cmd3, output3} });
commands.h
extern const std::string cmd1;
extern const std::string cmd2;
extern const std::string cmd3;
commands.cpp
std::string cmd1 = "-text1";
std::string cmd2 = "-text2";
std::string cmd3 = "-text3";
It compiles fine, however, in debug, cmdOutputMap has a size of 1, with the only key being "".
If, instead of using the variables cmd1, cmd2, cmd3, I use their values (see below), then cmdOutputMap has a size of 3, with the right keys populated.
map<const string, vector<string>> cmdOutputMap({ {"-text1", output1},
{"-text2", output2},
{"-text3", output3} });
Is it wrong to initialize a std::map with variables?
Thanks,
Fred