简体   繁体   中英

std::bind to std::function?

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM