std::bind to std::function?

只谈情不闲聊 提交于 2019-12-21 03:19:10

问题


I get a compile error using this:

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);

The error is:

/usr/include/c++/4.6/functional:1764:40: error: no match for call to '(std::_Bind(int)>) (int)'

Can someone tell me how to convert a std::bind into a std::function?


回答1:


std::function<int(int)> bar = std::bind(foo, 2, std::placeholders::_1);


来源:https://stackoverflow.com/questions/11372855/stdbind-to-stdfunction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!