如何将模板指针指向成员函数?以模板非模板参数为函数模板
通过模板我的意思是以下类型事先不知道:
- 模板PARAM
T
是类指针的成员 - 模板PARAM
R
是返回类型 - 可变参数模板PARAM
Args...
是参数
说明问题的非工作代码:
template <???>
void pmf_tparam() {}
// this works, but it's a function parameter, not a template parameter
template <class T, typename R, typename... Args>
void pmf_param(R (T::*pmf)(Args...)) {}
struct A {
void f(int) {}
};
int main() {
pmf_tparam<&A::f>(); // What I'm looking for
pmf_param(&A::f); // This works but that's not what I'm looking for
return 0;
}
是否有可能在C++ 11中实现所需的行为?
你需要这是一个真正的功能?我已经离开了C++游戏一段时间了,但是如果你让你的函数成为一个类并且重写'operator()'以便它看起来像一个函数一样工作呢? – Falmarri