关于STL 地图 & hash_地图在头文件中定义的有关问题

关于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

求问,应该怎么使用?
------解决方案--------------------
楼主,你在哪本教材学的在函数外面给变量赋值?
------解决方案--------------------
LZ,还是再去看看书。。。全局变量只能在定义时候才能在函数外赋值,都定义完了还能在函数外赋值?
------解决方案--------------------
推荐你一种方法,也是可以自动初始化

class InitHashmap
{
public:
InitHashmap(std::hash_map<string, const char*>& str_map)
{
str_map["key1"] = "Value1";
}
};

std::hash_map<string, const char*> HashMapTest;

InitHashmap init(HashMapTest);
------解决方案--------------------
引用:
Quote: 引用:

楼主,你在哪本教材学的在函数外面给变量赋值?

全局变量,好吗?

就算全局变量也只能初始化,不能赋值。
要么是书太烂,要么是你看书不仔细