关于c++ 模板作为函数指针参数

2025-05-02 00:33:47
推荐回答(1个)
回答1:

改成如下
template
void getKeyEvent( T *pClass,void (T::*pfun)(int))
{
static struct input_event ev_key;
int key;
int count = read(keyFd,&ev_key,sizeof(struct input_event));
for(int i=0; i<(int)count/sizeof(struct input_event); i++)
{
key=getKyes(ev_key);
if(key!=0)
(pClass->*pfun)(key); //这里改成这样的
}
}
然后在类KeypadThread里面调用
getKeyEvent(this,&KeypadThread::getKey); //这里改成这样的