#include <string>
using namespace std;
typedef std::map<const char*, char* > StringMap;
StringMap attrBase;
attrBase["MsName"] = "ms04"; //编译错误: error: expected constructor, destructor, or type conversion before token;
原因在于把这个初始化Map变量看作类似于字符串数组初始化一样放在函数的外面造成这样的问题,放在函数里面编译,问题终于解决
本文探讨了在C++中使用标准模板库(STL) map类型时的一个常见编译错误,并解释了为什么不能将map初始化放在函数之外的原因。通过一个具体的例子,展示了正确的初始化方式。
1197

被折叠的 条评论
为什么被折叠?



