执行 set_difference 时出错:变量结果不是结构

2024-05-01

我在函数外部全局声明了一个设置变量。

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.

edit:

删除下划线不起作用。 我现在尝试:

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.

这段代码为我编译。 http://ideone.com/z3qsS

也许你的编译器抱怨你的下划线用法?因为它说:

多变的result不是一个结构。

鉴于你声明_result_.

See 在 C++ 标识符中使用下划线的规则是什么? https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier(根据推荐Mat https://stackoverflow.com/users/635608/mat).

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

执行 set_difference 时出错:变量结果不是结构 的相关文章

随机推荐