C++ passing method pointer as template argument

前端 未结 5 982
攒了一身酷
攒了一身酷 2021-01-19 23:44

I have a caller function like this:

template
void CallMethod(T *object){
    (object->*method)(args);
}
         


        
5条回答
  •  温柔的废话
    2021-01-20 00:44

    All template parameters must be known at compile time. So if method is really a variable and not a particular function, there is no way to do what you want.

    Instead, you may be able to make a template struct which has a pointer to member function as a member and implements an operator() which acts similarly to CallMethod.

提交回复
热议问题