boost bind

World7th 2014-03-18 02:28:12
#include<boost/bind.hpp>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace boost;
using namespace std;

struct point
{
int x,y;
point(int a=0,int b=0):x(a),y(b){}
void print(){
cout << "(" << x << "," << y << ")\n";
}
};

int main()
{
vector<point> v(10);
//for_each的时候只需要_1就可以了
for_each(v.begin(),v.end(),bind(&point::print,_1));

}

如下面一行程序代码中,
for_each(v.begin(),v.end(),bind(&point::print,_1));
_1代表什么含义,是代表哪个参数
...全文
169 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
feihuadao 2014-03-19
  • 打赏
  • 举报
回复
引用 5 楼 mujiok2003 的回复:
引用
如下面一行程序代码中, for_each(v.begin(),v.end(),bind(&point::print,_1)); _1代表什么含义,是代表哪个参数
&point::print需要对象来调用, _1就是那个对象或者对象指针。
是啊,_1代表绑定的函数的第一个参数,以此类推。对于成员函数,明显是this嘛。
mujiok2003 2014-03-18
  • 打赏
  • 举报
回复
引用
如下面一行程序代码中, for_each(v.begin(),v.end(),bind(&point::print,_1)); _1代表什么含义,是代表哪个参数
&point::print需要对象来调用, _1就是那个对象或者对象指针。
taodm 2014-03-18
  • 打赏
  • 举报
回复
boost的bind库有中文文档的,自己认真看一下就搞清楚了。
turing-complete 2014-03-18
  • 打赏
  • 举报
回复
引用 2 楼 World7th 的回复:
知道是占位符,那是代表哪个参数呢?
你看看for_each的签名不就知道了,再者,你这个占位符_1前面还少个参数吧。
World7th 2014-03-18
  • 打赏
  • 举报
回复
知道是占位符,那是代表哪个参数呢?
昵称很不好取 2014-03-18
  • 打赏
  • 举报
回复
占位符,传参数用的吧
1.41.0版本的中文文档20091225,已完成翻译91个库. 汉化 boost 文档,致力 boost 推广。 如果你对本项目有兴趣,欢迎加入,相关说明请查阅项目论坛: https://groups.google.com/ 到目前为止,各人贡献的译文如下: 贡献者 贡献的译文 alai04 accumulators, any, assign, bimap, call_traits, circular_buffer, compatibility, concept check, config, conversion, date_time, filesystem, foreach, function_types, functional, integer, intrusive, io state savers, iostreams, iterators, minmax, mpl, multi_array, multi_index, numeric/conversion, operators, optional, pointer container, pool, preprocessor, program_options, property map, property_tree, proto, range, rational, scope_exit, serialization, spirit, statechart, swap, system, tokenizer, TR1, tribool, unordered, utility, value_initialized, variant, wave, xpressive fatalerror99 array, bind & mem_fn, dynamic_bitset, function, functional/hash, in_place_factory & typed_in_place_factory, lambda, ref, smart_ptr, static_assert, string_algo, type_traits, typeof farproc compressed_pair, crc, enable_if blackjazz07 conversion/lexical_cast, format hzjboost tuple xuwaters parameter, timer 金庆 python, signals, signals2 zhaohongchao exception, gil luckycat06 interval, math, math/complex number algorithms, math/common_factor, math/octonion, math/quaternion, math/special_functions, math/statistical, uBLAS lixin regex, test, units evy.wang thread xiaq random 水的影子 flyweight

65,208

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧