0

set_intersection() 関数を使用しようとしています。私のコードは以下のようになります

set<int> IntersectionSet;

for(map<string, set<int>>::iterator it = mapArtist.begin() ; it != mapArtist.end() ; ++it)
{       
    for(map<string, set<int>>::iterator it2 = it ; ++it2 != mapArtist.end() ; ++it2)
    {
        set<int>::iterator iter = set_intersection(it->second.begin(), it->second.end(), it2->second.begin(), it2->second.end(), std::inserter(IntersectionSet, IntersectionSet.begin()));
        if(IntersectionSet.size() >= 300) cout << it->first << "    " << it2->first << "\n";
        IntersectionSet.clear();
    }
}

ここでの問題は、行にあるようです

set<int>::iterator iter = set_intersection(it->second.begin(), it->second.end(), it2->second.begin(), it2->second.end(), std::inserter(IntersectionSet, IntersectionSet.begin()));

このサイトで見た他のページでの使用と比較して、これは正しいようです。コンパイル中に次のエラーが発生します

1>c:\users\Machine\documents\visual studio 2010\projects\artists\artists\artists.cpp(109): error C2440: 'initializing' : cannot convert from 'std::insert_iterator<_Container>' to 'std::_Tree_const_iterator<_Mytree>'
1>          with
1>          [
1>              _Container=std::set<int>
1>          ]
1>          and
1>          [
1>              _Mytree=std::_Tree_val<std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>>
1>          ]
1>          No constructor could take the source type, or constructor overload resolution was ambiguous
1>
1>Build FAILED.

ここで何が欠けていますか?ありがとう。

4

1 に答える 1

3

問題はここにあります:

set<int>::iterator iter = set_intersection(/*...*/);

std::set_intersectionstd::insert_iteratorは、コードではではなく である挿入子を返しますstd::set<int>::iterator

を使用iterしないので、戻り値に対して何もする必要はまったくありません。電話するだけstd::set_intersectionです。

于 2012-08-25T17:28:06.323 に答える