#include "stdafx.h"
#include "iostream"
using namespace std;
#define BOOL int
#define TRUE 1
#define FALSE 0
//1.先声明一个函数指针类型
typedef int (*TESTCALLBACK)(BOOL);
//2.然后声明并实现被调用函数
int CallbackTest1(BOOL bIs);
int CallbackTest1(BOOL bIs)
{
return bIs+1;
}
int CallbackTest2(BOOL bIs)
{
return bIs-100;
}
//3.声明调用函数
int test(TESTCALLBACK lpTest);
//int test(TESTCALLBACK=CallbackTest1);//使用缺省参数
//4.在调用函数的实现中,直接使用函数指针即可
int test(TESTCALLBACK lpTest)
{
return lpTest(TRUE);
}
int main(int argc, char* argv[])
{
//测试函数指针和回调
cout<<""<<test(CallbackTest1)<<endl;
cout<<""<<test(CallbackTest2)<<endl;
//cout<<""<<test()<<endl;//使用缺省参数
return 0;
}