更新时间:2022-01-14 00:39:48
我认为类模板是不可能的,因为你必须明确指定成员函数类型.
I think it's impossible for class template, because you have to specify the member function type explicitly.
模板函数可以帮助您进行参数推导:
Template function could help you lot with the argument deduction:
template<typename T, typename M, typename... Args>
void invoke (T& Object, M Method, Args&&... A)
{
(void)(Object.*Method)(std::forward<Args>(A)...);
}
然后
invoke(myObj, &Object::MyMethod, 10);