我使用这个得到编译错误:
std::vector<std::function<int(int)>> functions;
std::function<int(int, int)> foo = [](int a, int b){ return a + b; };
std::function<int(int)> bar = std::bind(foo, 2);
functions.push_back(bar);
错误是:
/ usr / include / c ++ / 4.6 / functional:1764:40:错误:无法调用'(std :: _ Bind(int)&gt;)(int)'
有人可以告诉我如何将std::bind
转换为std::function
吗?
答案 0 :(得分:20)
std::function<int(int)> bar = std::bind(foo, 2, std::placeholders::_1);