質問

以下に示すように挿入できないのはなぜですか?

#include <map>

struct something {

} some_object;

typedef std::map<std::string, something*> list;
typedef std::pair<std::string, something*> pair;

int main()
{
    list l;
    pair p("abc", &some_object); // working fine!!!
    l.insert(p); // 17 errors

    return 0;
}

Visual Studioでは多くのエラーが発生しますが、何も理解できません。最初のものは:

error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'

もっと投稿できますが、ここでスパムを送信したくありません。ご協力ありがとうございます。

役に立ちましたか?

解決

する必要があります

#include <string>

他のヒント

この行を変更します:

typedef std::pair<std::string, something*> pair;

実装の詳細を伝えています。これは今後のすべてのバージョンのライブラリに常に当てはまると確信していますか?そのようにコードを密結合することは悪い考えです。

これを試してください:

typedef list::value_type pair;

PS。 「名前空間」に入れる型の名前の最初の選択は「リスト」ではありません。独自の名前空間に置くか、「MyList」と呼びます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top