<pre name="code" class="plain">类成员函数做回调函数有如下两种方法:
1、成员函数是静态函数,但是静态函数只能访问类成员的静态变量和静态函数
2、成员函数对用类对象,用对象调用赋值后的函数指针
举例说明如下:
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
class test
{
public:
test(){}
~test(){}
public:
void func()
{
printf("xxxxxxxxxxxxx\n");
}
static void func1()
{
printf("aaaaaaaaaaaaa\n");
}
};
typedef void (test::*FUNC)();
void print(test *a, FUNC p)
{
(a->*p)();
}
int main()
{
test a;
print(&a, &test::func);
typedef void(*FUNC1)();
FUNC1 b = &test::func1;
b();
system("pause");
return 0;
}