【发布时间】:2018-03-20 17:24:03
【问题描述】:
使用以下类,我希望能够创建指定Foo() 的实例来存储和调用函数,但是如何将必要的参数传递给函数call?
template<class R, class... Args> struct Foo {
std::function<R(Args...)> func;
Foo(const std::function<R(Args...)> &funcIn) : func(funcIn) {}
R call(Args...) {
return func(/* ? */);
}
};
例如:
int main() {
typedef typename Foo<int(int)> Bar;
Bar x([](int y, int z){return y + z + 2;});
std::cout << x.call(12, 7);
return 0;
}
【问题讨论】:
-
制作它short
标签: c++ c++11 templates variadic-templates multiple-arguments