c++ - 将绑定(bind)函数分配给 std::function

标签 c++ templates vector compiler-errors

这不会为我编译:

int i = 1;
std::function<void(std::vector<int>&)> execute = std::bind(append<int>, _1, std::ref(i));

附加有签名的地方:

template<class T>
void append(std::vector<T>& container, const T& valueToAppend)

我做错了什么很明显吗?

编译器错误是:

error C2664: 'void (std::vector<_Ty> &,const T &)' : cannot convert parameter 1 from 'boost::arg<I>' to 'std::vector<_Ty> &'
1>          with
1>          [
1>              _Ty=int,
1>              T=int
1>          ]
1>          and
1>          [
1>              I=1
1>          ]
1>          and
1>          [
1>              _Ty=int
1>          ]

最佳答案

你需要

using namespace std::placeholders;

关于c++ - 将绑定(bind)函数分配给 std::function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12462271/

相关文章:

c++ - CLion 会自动从标准输入打印回输入,是否有任何解决方法?

c++ - 为什么采用迭代器的构造函数要求元素是 EmplaceConstructible?

c++ - 在大模板类中专门化单个方法

c++ - 访问 vector 容器的元素时发生运行时错误

haskell - 惰性数据类型的内存使用情况

java - 如何使用paintComponent(Graphics g)绘制存储在 vector 中的对象

c++ - 多次指定对象 - 从 C++ 调用 asm 代码时未解析的外部符号

C++ 模板的类(非对象)参数

c++ - 不考虑 noexcept 规范的过载

c++ - 内存管理和 std::allocator