回调函数
来源:互联网 发布:苏联数学 知乎 编辑:程序博客网 时间:2024/06/07 00:07
// 01.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <stdio.h>//方法指针的格式为:int (*ptr)(char *p) 即:返回值(指针名)(参数列表) typedef int (*CallBackFun)(char *p); //为回调函数命名,类型命名为 CallBackFun,参数为char *p //方法 Afun,格式符合 CallBackFun 的格式,因此可以看作是一个 CallBackFun 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 *)) //或者是int call2(char *p, int (*ptr)(char *)) 同时ptr可以任意取名 { printf("==============\n%s\n", p); ptr(p); // <<===>> (*ptr)(p);return 0;} int main(int argc, char* argv[]){char *p = "hello"; call(Afun, p); call(Cfun, p); call2(p, Afun); call2(p, Cfun); return 0;}
0 0
- .NET 回调函数
- 回调函数
- 回调函数
- 回调函数概念
- 回调函数
- 回调函数
- 回调函数
- 回调函数 相关
- delphi 回调函数
- 回调函数
- 回调函数
- 回调函数学习
- 回调函数
- 关于回调函数
- 透析回调函数
- 回调函数
- 什么是回调函数
- 回调函数
- UIImageView基础详解
- iOS KVC & KVO
- 使用NSURLSession实现下载类的封装
- C++11新特性
- 用Myeclipse运行项目报getClassInstance Line: 209 - com/opensymphony/xwork2/spring/SpringObject错
- 回调函数
- vmdk格式转换 kvm启动
- volatile关键字解析
- Android关闭AlertDialog的方法
- 杜绝假死,Tomcat容器做到自我保护,设置最大连接数
- Linux vmstat命令实战详解
- Oracle与MySQL字符串拼接
- 数据结构和算法学习第2天:栈的相关知识
- 2016太原网络营销师郭文军分享网站图片代码优化