bind function adapter (included <functional>)
Introduce:
bind(op, args, …) Binds args to op
Simple Code
int>(), std::placeholders::_1, 10);
cout<<pfn(7); // 17
cout<<pfn(7); // 17
Note that bind() internally copies passed arguments. To let the function object use a reference to a passed argument, use ref() or cref()
int i = 1;
prf(i);
cout<<i<<endl;// 2
For member function
return 0;
}
Note: the member funciton should be const function.
Note that you can also pass pointers to objects and even smart pointers to bind():
)};
for_each(vps.begin(), vps.end(), bind(&BindPerson::Print, _1));