8

静的マップを C++ メンバーとして使用できません。私のヘッダーファイルは次のとおりです。

class Article
{
public:
//
static map<string,Article*> dictionary;
....
....   
};

私のコンストラクターでは、最初に次のメソッドを呼び出します。

 void Article::InitializeDictionary()
 {
   #ifndef DICT
   #define DICT
   map<string,Article*> Article::dictionary;
   #endif
 }

これに関する他の投稿に基づいて、静的メンバーを宣言することになっていますが、これを実行しようとすると、次のエラーが発生します。

Error   1   error C2655: 'Article::dictionary' : definition or redeclaration illegal in current scope   c:\.......\article.cpp  88  1

関数を次のように変更すると:

void Article::InitializeDictionary()
{
    #ifndef DICT
    #define DICT
    Article::dictionary["null"] = 0;
    #endif
}

次のエラーが表示されます。

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)

私に何ができるかについてのアイデアはありますか?

4

2 に答える 2