我已经在全局函数之外声明了一个 set 变量。
std::set<std::string> s1;
std::set<std::string> s2;
std::set<std::string> intersect;
std::set<std::string> _result_; //here is the declaration
现在我尝试在函数中填充该结构。
s1.insert("1-1");
s2.insert("1-1");
std::set_intersection( s1.begin(), s1.end(), s2.begin(), s2.end(),std::insert_iterator< std::set<std::string> >( intersect, intersect.begin() ) );
std::set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(),std::inserter(_result_, _result_.end()));//this is where the error is coming.
我得到这个编译错误:
"cacup_bsc.cc", line 6572: Error: Variable result is not a structure.
编辑:
删除下划线不起作用。我现在尝试了:
std::set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(),std::insert_iterator< std::set<std::string> >(result_, result_.end() ) );
这给了我另一个编译错误。:
"/export/SunStudio/SUNWspro/prod/include/CC/Cstd/./algorithm.cc", line 2161: Error: Overloading ambiguity between "std::copy<__rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std::less<std::string>, std::allocator<std::string>>::const_iterator, std::insert_iterator<std::set<std::string>>>(__rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std::less<std::string>, std::allocator<std::string>>::const_iterator, __rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std::less<std::string>, std::allocator<std::string>>::const_iterator, std::insert_iterator<std::set<std::string>>)" and "copy<__rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std::less<std::string>, std::allocator<std::string>>::const_iterator, std::insert_iterator<std::set<std::string>>>(__rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std::less<std::string>, std::allocator<std::string>>::const_iterator, __rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std::less<std::string>, std::allocator<std::string>>::const_iterator, std::insert_iterator<std::set<std::string>>)".
"cacup_bsc.cc", line 6572: Where: While instantiating "std::set_difference<__rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std::less<std::string>, std::allocator<std::string>>::const_iterator, __rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std::less<std::string>, std::allocator<std::string>>::const_iterator, std::insert_iterator<std::set<std::string>>>(__rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std::less<std::string>, std::allocator<std::string>>::const_iterator, __rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std::less<std::string>, std::allocator<std::string>>::const_iterator, __rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std::less<std::string>, std::allocator<std::string>>::const_iterator, __rwstd::__rb_tree<std::string, std::string, __rwstd::__ident<std::string, std::string>, std::less<std::string>, std::allocator<std::string>>::const_iterator, std::insert_iterator<std::set<std::string>>)".
"cacup_bsc.cc", line 6572: Where: Instantiated from non-template code.