#include <stdio.h>
typedef int (*CallBackFun)(char *p);
int Afun(char *p) {
printf("Afun 回调打印出字符%s!\n", p);
return 0;
}
int Cfun(char *p) {
printf("Cfun 回调打印:%s, Nice to meet you!\n", p);
return 0;
}
int call(CallBackFun pCallBack, char *p) { // 执行回调函数,方式一:通过命名方式
//printf("call 直接打印出字符%s!\n", p);
pCallBack(p);
return 0;
}
int call2(char *p, int(*ptr)(char *p) ) { // 执行回调函数,方式二:直接通过方法指针
//printf("==============\n", p);
(*ptr)(p);
return 0;
}
int main() {
char *p = "hello";
call(Afun, p);
call(Cfun, p);
call2(p, Afun);
call2(p, Cfun);
return 0;
}
http://hi.baidu.com/helloweenpad/blog/item/d96d13fb4b2276809f514607.html/cmtid/61eba60ba34a7530b0351d68