【发布时间】:2012-08-07 19:48:12
【问题描述】:
我有一个参数个数不定的成员函数,存储在std::function中,我想绑定实例,得到一个独立的函数对象。
template <class T, class R, class... Args>
void connect(const T& t, std::function<R(const T&, Args...)> f) {
std::function<R(Args...)> = /* bind the instance c into the function? */
}
// ...
Class c;
connect(c, &Class::foo);
对于固定数量的参数,我会使用std::bind,但我不知道如何为可变参数执行此操作。
【问题讨论】:
-
你到底是怎么得到
Args...的? -
好的,我写的代码不同,希望这样更容易理解。
-
是的。并使解决方案相当容易。 :)
-
@Xeo 这就是我喜欢听到的:D
标签: c++ templates c++11 variadic-templates std-function