I have a link error on the following code.
header file
//we have a static class member std::map that I want to be read-only
//the enums are numeric but not sequential
typedef std::map<MyEnumType, std::string> MyStdMapType
class MyClass { static const MyStdMapType myMap; }
source file
//populate - static var outside of class
const MyStdMapType MyClass::myMap = { {enumVal1, str1}, ... }
Then, later, I want to iterate through the map
for (MyStdMapType::const_iterator iter = MyClass::myMap.begin(); iter != MyClass::myMap.end(); iter++)
{
<stuff>
}
The "for" line is giving a link error. If I comment the line out, it compiles!:
error LNK2001: unresolved external symbol "public: static class std::map<enum MyEnumType,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<enum MyEnumType>,class std::allocator<struct std::pair<enum MyEnumType const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > > const MyClass::myMap" (?myMap@MyClass@@2V?$map@W4MyEnum@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@U?$less@W4MyEnum@@@3@V?$allocator@U?$pair@$$CBW4MyEnum@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@std@@@3@@std@@B)