std :: bind to std :: function? [英] std::bind to std::function?

查看:243
本文介绍了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){};
std::function<int(int)> bar = std::bind(foo, 2);

functions.push_back(bar);

我得到的错误是:

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

有人可以告诉我如何转换std: :bind into a std :: function?

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

这篇关于std :: bind to std :: function?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆