【发布时间】:2012-09-17 15:16:44
【问题描述】:
这不会为我编译:
int i = 1;
std::function<void(std::vector<int>&)> execute = std::bind(append<int>, _1, std::ref(i));
其中 append 有签名:
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 指令。例如,您的示例代码从不调用 Boost,但消息错误似乎表明您正在使用它的库之一。
-
嗯。在 Visual Studio 2010 中运行良好。您使用的是什么编译器?您收到什么错误消息?
标签: c++ templates vector compiler-errors