C++ passing method pointer as template argument

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

I have a caller function like this:

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


        
5条回答
  •  梦毁少年i
    2021-01-20 00:42

    First, please create typedefs http://www.parashift.com/c++-faq-lite/pointers-to-members.html#faq-33.5

    Second,

    void (*function)(A *) = &CallMethod;
    

    In this case, method is a variable and variables can not be template arguments. I haven't tested it but perhaps you could try...

    void (*function)(A *) = &CallMethod;
    

提交回复
热议问题