Cpp initialize std::map in header

  c++, header, initialization

I want to initialize a std::map in my_cpp.h header file:

std::map<std::string, double> my_map;
my_map["name1"] = 0;
my_map["name2"] = 0;

But there was a compile error showed up:

error: ‘my_map’ does not name a type

Can someone explain why this not work for a C++ newbie?
Thanks

Source: Windows Questions C++

LEAVE A COMMENT