个人觉得类成员函数的指针只是一种匹配的形式。把一个类的成员函数的定义形式记取出来,然后交给某个类的对象去调用之。
代码片段:
class abc;
typedef void (abc::*FUNC)(void *, constchar *,constchar *);
struct option {
//void (abc::*func)(void *, const char *, const char *);
FUNC func;
};
class abc {
int i;
public:
abc()
{
i = 1024;
option o;
o.func = &abc::func;//注意这里的赋值形式
(this->*o.func)(NULL, NULL, NULL);//注意这里的调用形式
//FUNC f = o.func;
//(this->*f)(NULL, NULL, NULL);
}
void func(void *context, constchar *name,constchar *value)
{
printf("hello%d\n", i++);
}
};
int _tmain(int argc, _TCHAR* argv[])
{
abc abc_obj;
option o;
o.func = &abc::func;
(abc_obj.*o.func)(NULL, NULL, NULL);
FUNC f = o.func;
(abc_obj.*f)(NULL, NULL, NULL);
return 0;
}