错误:重载“std :: copy之间的歧义

时间:2011-12-26 11:11:09

标签: c++ stl inserter

我有一个如下代码:

#include<set>
#include<iterator>

std::set<std::string> s1;
std::set<std::string> s2;   
std::set<std::string> myresult;

void some_func() {
    std::set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(),std::inserter(myresult,myresult.begin()));
}

这给了我编译错误:

/export/SunStudio/SUNWspro/prod/include/CC/Cstd/./algorithm.cc" ;,第2161行:错误:重载&#34; std :: copy&lt; __ rwstd :: __ rb_tree&lt; std :: string之间的歧义,std :: string,__ rwstd :: __ ident&lt; std :: string,std :: string&gt;,std :: less&lt; std :: string&gt;,std :: allocator&lt; std :: string&gt;&gt; :: const_iterator,std :: insert_iterator&lt; std :: set&lt; std :: string&gt;&gt;&gt;(__ rwstd :: __ rb_tree&lt; std :: string,std :: string,__ rwstd :: __ ident&lt; std :: string,std :: string&gt;, std :: less&lt; std :: string&gt;,std :: allocator&lt; std :: string&gt;&gt; :: const_iterator,__ rwstd :: __ rb_tree&lt; std :: string,std :: string,__ rwstd :: __ ident&lt; std :: string,std :: string&gt;,std :: less&lt; std :: string&gt;,std :: allocator&lt; std :: string&gt;&gt; :: const_iterator,std :: insert_iterator&lt; std :: set&lt; std :: string&gt; &GT;)&#34;和&#34;复制&lt; __ rwstd :: __ rb_tree&lt; std :: string,std :: string,__ rwstd :: __ ident&lt; std :: string,std :: string&gt;,std :: less&lt; std :: string&gt;,std :: allocator&lt; std :: string&gt;&gt; :: const_iterator,std :: insert_iterator&lt; std :: set&lt; std :: string&gt;&gt;&gt;(__ rwstd :: __ rb_tree&lt; std :: string,std :: string, __rwstd :: __ ident&lt; std :: string,std :: string&gt;,std :: less&lt; std :: string&gt;,std :: allocator&lt; std :: string&gt;&gt; :: const_iterator,__ rwstd :: __ rb_tree&lt; std: :string,std :: string,__ rwstd :: __ ident&lt; std :: string,std :: string&gt;,std :: less&lt; std :: string&gt ;,std :: allocator&lt; std :: string&gt;&gt; :: const_iterator ,std :: insert_iterator&lt; std :: set&lt; std :: string&gt;&gt;)&#34;。

1 个答案:

答案 0 :(得分:0)

您忘了添加

#include<algorithm>

代码。