#include <iostream>
using namespace std;
typedef void (*FuncPtr)(void); //定义回调函数,定义一个函数参数为空,返回值为空的函数指针,参数和返回值形式都一样,但功能不确定的函数
class Test
{
public:
static void println(void) //作为参数的类成员函数必须声明为静态的
{
cout << "callback" << endl;
}
};
void FuncType(FuncPtr p)
{
cout << "FuncType" << endl;
p(); //调用回调函数
}
int main()
{
FuncType(Test::println); //不要带括号
return 0;
}
输出:
FuncType
callback