我有一个这样初始化的全局变量:
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";
它可以很好地进行编译,但是,在调试中,cmdOutputMap的大小为1,唯一的键是“”。
如果我不是使用变量cmd1,cmd2,cmd3,而是使用它们的值(请参见下文),则cmdOutputMap的大小为3,并填充了右键。
map<const string, vector<string>> cmdOutputMap({ {"-text1", output1},
{"-text2", output2},
{"-text3", output3} });
用变量初始化std :: map是否错误?
谢谢
弗雷德