I'm having trouble using a static map as a C++ member. My header file is:
class Article
{
public:
//
static map<string,Article*> dictionary;
....
....
};
In my constructor I call the following method first:
void Article::InitializeDictionary()
{
#ifndef DICT
#define DICT
map<string,Article*> Article::dictionary;
#endif
}
Based on other posts about this I am supposed to declare the static member but when I try to do this I get the following error:
Error 1 error C2655: 'Article::dictionary' : definition or redeclaration illegal in current scope c:\.......\article.cpp 88 1
If I change the function to the following:
void Article::InitializeDictionary()
{
#ifndef DICT
#define DICT
Article::dictionary["null"] = 0;
#endif
}
I get this error:
Error 1 error LNK2001: unresolved external symbol "public: static class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class Article *,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class Article *> > > Article::dictionary" (?dictionary@Article@@2V?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAVArticle@@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAVArticle@@@std@@@2@@std@@A)
Any ideas on what I can do?