C++11 std::bind(延迟计算)-GCC 4.9编译通过

tech2022-09-02  112

bind的思想实际上是一种延迟计算的思想,将可调用对象保存起来,然后在需要的时候再调用。 std::bind可以说是一个可调用实体的adapter。它可以预先把指定可调用实体的某些参数绑定到已有的变量,产生一个新的可调用实体,这种机制在回调函数的使用过程中颇为有用。 bind的语法格式: auto newCallable = bind(callable, arg_list); 一个简单的例子:

#include <iostream> #include <functional> using namespace std; int Func(int x, int y
最新回复(0)