VC ++ 2010でコンパイルするために、このようなコードスニペットがあります。
std::set s1;
std::set s2;
std::set res_set;
std::set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), res_set.begin());
私が知る限り、これはうまくいくはずです。しかし、私はビルドエラーを取得します:
c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm(4494): error C3892: 'std::_Tree_const_iterator<_Mytree>::operator *' : you cannot assign to a variable that is const
1> with
1> [
1> _Mytree=std::_Tree_val,std::allocator,false>>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm(4522) : see reference to function template instantiation '_OutIt std::_Set_intersection<_InIt1,_InIt2,_OutIt>(_InIt1,_InIt1,_InIt2,_InIt2,_OutIt)' being compiled
1> with
1> [
1> _OutIt=std::_Tree_const_iterator,std::allocator,false>>>,
1> _InIt1=std::_Tree_unchecked_const_iterator,std::allocator,false>>>,
1> _InIt2=std::_Tree_unchecked_const_iterator,std::allocator,false>>>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm(4549) : see reference to function template instantiation '_OutIt std::_Set_intersection1,std::_Tree_unchecked_const_iterator<_Mytree>,_OutIt>(_InIt1,_InIt1,_InIt2,_InIt2,_OutIt,std::tr1::true_type)' being compiled
1> with
1> [
1> _OutIt=std::_Tree_const_iterator,std::allocator,false>>>,
1> _Mytree=std::_Tree_val,std::allocator,false>>,
1> _InIt1=std::_Tree_unchecked_const_iterator,std::allocator,false>>>,
1> _InIt2=std::_Tree_unchecked_const_iterator,std::allocator,false>>>
1> ]
1> c:\p4r\pkrcode\depot\dev\stats\poker\protype\statserver\achievementmanager.cpp(175) : see reference to function template instantiation '_OutIt std::set_intersection,std::_Tree_const_iterator<_Mytree>,std::_Tree_const_iterator<_Mytree>>(_InIt1,_InIt1,_InIt2,_InIt2,_OutIt)' being compiled
1> with
1> [
1> _OutIt=std::_Tree_const_iterator,std::allocator,false>>>,
1> _Mytree=std::_Tree_val,std::allocator,false>>,
1> _InIt1=std::_Tree_const_iterator,std::allocator,false>>>,
1> _InIt2=std::_Tree_const_iterator,std::allocator,false>>>
1> ]
そのために、明示的なテンプレートパラメータ宣言を行いました。
std::set_intersection::const_iterator, std::set::const_iterator, std::set::iterator>(
s1.begin(), s1.end(), s2.begin(), s2.end(), res_set.begin()
);
しかし、私は同じエラーがあります。ここでの問題は、2番目のケースでは、const_iteratorを渡すと、パラメータ型が一致しないため、const_iteratorとiteratorの間の変換エラーで失敗するはずです。私はここで何が欠けていますか? (私はset_intersectionの "inserter"形式について知っていますが、ここで何が間違っているかを知りたい)