提高::绑定和放大器;性病::设置::算编译出错 [英] boost::bind & std::set::count compile error
本文介绍了提高::绑定和放大器;性病::设置::算编译出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能有人点我,拜托,有什么区别制作一套仿::插入和设置之间::算在下面的片段?
的typedef的std ::设为<标准::字符串> S_TYPE;
的typedef的std ::对< S_TYPE:迭代,布尔>(S_TYPE :: * insert_fp)(常量S_TYPE :: VALUE_TYPE&安培;);
的typedef S_TYPE :: SIZE_TYPE(S_TYPE :: * count_fp)(常量S_TYPE :: VALUE_TYPE&安培;);的std ::矢量<标准::字符串> s_vector;
的std ::集<标准::字符串> s_set;的std :: for_each的(s_vector.begin(),s_vector.end()的boost ::绑定(的static_cast< insert_fp>(安培; S_TYPE ::插入),放大器; s_set,_1));
的std :: for_each的(s_vector.begin(),s_vector.end()的boost ::绑定(的static_cast< count_fp>(安培; S_TYPE ::计数),放大器; s_set,_1));
给出:
错误C2440:'的static_cast:无法从重载函数转换为count_fp
与此名称的所有功能都在范围与目标类型
解决方案
我不知道你要怎么做,但下面的工作对我来说没有强制转换:
INT的main()
{
的std ::矢量<标准::字符串>向量;
的std ::集<标准::字符串>组; 的std :: for_each的(vector.begin(),s_vector.end()
提高::绑定(安培;的std ::设为<标准::字符串> ::插入,与和设定,_1));
的std :: for_each的(vector.begin(),s_vector.end()
提高::绑定(安培;的std ::设为<标准::字符串> ::数,设置,_1)); 返回0;
}
Could anybody point me, please, what the difference is between making functor of set::insert and set::count in the below fragment?
typedef std::set<std::string> s_type;
typedef std::pair<s_type::iterator, bool>(s_type::*insert_fp)(const s_type::value_type&);
typedef s_type::size_type(s_type::*count_fp)(const s_type::value_type&);
std::vector<std::string> s_vector;
std::set<std::string> s_set;
std::for_each(s_vector.begin(), s_vector.end(), boost::bind(static_cast<insert_fp>(&s_type::insert), &s_set, _1));
std::for_each(s_vector.begin(), s_vector.end(), boost::bind(static_cast<count_fp>(&s_type::count), &s_set, _1));
Gives:
error C2440: 'static_cast' : cannot convert from 'overloaded-function' to 'count_fp'
None of the functions with this name in scope match the target type
解决方案
I don't know what you're trying to do but the following works for me without casts:
int main()
{
std::vector<std::string> vector;
std::set<std::string> set;
std::for_each(vector.begin(), s_vector.end(),
boost::bind(&std::set<std::string>::insert, &set, _1));
std::for_each(vector.begin(), s_vector.end(),
boost::bind(&std::set<std::string>::count, set, _1));
return 0;
}
这篇关于提高::绑定和放大器;性病::设置::算编译出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文