【发布时间】:2016-03-31 17:19:10
【问题描述】:
在stackoverflow 问题Template function that can take lambda or function pointer and deduce arguments for passing to another template 中有一个通过CreateFunctor 调用创建的仿函数对象。如何使用它来调用doSomething?
int main(){
auto f1 = CreateFunctor([](int a, int b){doSomething(a, b);}, 1, 2);
f1(1,2);
}
不起作用。
【问题讨论】:
-
最好把错误信息复制到这里。通过阅读错误消息,
Functor似乎没有operator(...)需要在f1(1,2)行调用它。另外,Set函数除了打印 'Set' 什么都不做……我想你需要的是std::bind,不需要自己写(cplusplus.com/reference/functional/bind/?kw=bind)