一、背景介绍:
函数指针始终不太灵活,它只能指向全局或静态函数,对于类成员函数、lambda表达式或其他可调用对象就无能为力了,因此,C++11推出了std::function与std::bind这两件大杀器...auto f1 = std::bind(f, _2, 42, _1, _3, n);
n = 10;
// 参数的对应关系为:1--》n3,2-->n1,42--->n2,1001-->...this
auto f3 = std::bind(&Foo::print_sum, &foo, 95, _1);
f3(5);
std::cout bind to...: 100
2) bind to a mem_fn that is a pointer to member function:
另一个是:可以使用std:ref和std:cref来使用引用。...::function bound_f = std::bind(f, n1, std::ref(n2), std::cref(n3));
n1 = 10;
n2 = 11;