std::bind to std::function?

2019-03-24 06:02发布

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条回答
等我变得足够好
2楼-- · 2019-03-24 06:11
std::function<int(int)> bar = std::bind(foo, 2, std::placeholders::_1);
查看更多
登录 后发表回答