关于STL map & hash_map在头文件中定义的问题
我有一些配置信息,需要在头文件中用到hash_map定义的,测试代码如下:
// .h
#ifndef __STL_MAPTEST_H__
#define __STL_MAPTEST_H__
#include <hash_map>
std::hash_map<std::string, const char*> HashMapTest;
HashMapTest["key1"] = "Value1";
#endif // __STL_MAPTEST_H__
把这个代码拿去编译,得到的错误如下:
1>e:\coding\cpp\cpptest\cpptest\stl_maptest.h(21): error C2057: 应输入常量表达式
1>e:\coding\cpp\cpptest\cpptest\stl_maptest.h(21): error C2466: 不能分配常量大小为 0 的数组
1>e:\coding\cpp\cpptest\cpptest\stl_maptest.h(21): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\coding\cpp\cpptest\cpptest\stl_maptest.h(21): error C2040: “HashMapTest”:“int []”与“stdext::hash_map<_Kty,_Ty>”的间接寻址级别不同
1> with
1> [
1> _Kty=std::string,
1> _Ty=char *
1> ]
1>e:\coding\cpp\cpptest\cpptest\stl_maptest.h(21): error C2440: “初始化”: 无法从“const char [20]”转换为“int []”
1> 没有使该转换得以执行的上下文
1>
1>生成失败。
测试环境为:windows 7 + vs2010
求问,应该怎么使用?