惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
D
DataBreaches.Net
F
Full Disclosure
腾讯CDC
博客园 - 【当耐特】
MyScale Blog
MyScale Blog
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
The Register - Security
The Register - Security
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
J
Java Code Geeks
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
博客园 - 三生石上(FineUI控件)
Know Your Adversary
Know Your Adversary
AWS News Blog
AWS News Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
O
OpenAI News
Project Zero
Project Zero
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Application and Cybersecurity Blog
Application and Cybersecurity Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
MongoDB | Blog
MongoDB | Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
Schneier on Security
Schneier on Security

博客园 - 火鸟

一点想法 无 SOAP 的 Web 服务(转) 关于手机电池的基本知识 国际标准组织高票接纳闪联为其成员 MPEG2 TS与ISMA的比较 9@9d无线连接上WWW网 P2P流媒体服务器 P2P IPTV技术进展 [转载]公司不是我的家 ARPA——美国国防部高级计划署,Advanced Research Projects Agency 共创软件联盟维护863开源项目 什么是IPO [转载]纵横捭阖C++之从异步谈起 nunit 2.2.7下载 在Cygwin环境下使用动态库的方法 新春愉快 用户属性“密码永不过期”修改方法 安装Tomcat过程中发现,出现using jvm.dl时进度条长时间不动,是什么原因? Microsoft ready to pull trigger on BizTalk beta
关于回调函数
火鸟 · 2005-12-15 · via 博客园 - 火鸟

我们在设计软件系统架构的时候,经常需要用到回调函数。例如,我们设计了一个库,封装了一些接口。客户程序调用这些接口,我们的库执行一系列业务逻辑,并在调用结束的时候通知客户程序。
为了便于理解回调函数,我设计以下简单的例子:

#include "stdafx.h"


// 函数指针
typedef int (*MYCALLBACK) (int a, int b); 

// 回调函数调用函数
// 可以看作是DLL提供的接口
void testCallback (MYCALLBACK fun)
{
    fun(
1,2);// 调用回调函数
}


// 回调函数
int callback(int a, int b)
{
    printf (
"我被回调了!\n");
    
return a + b;
}


int callback2(int a, int b)
{
    printf (
"我也被回调了!\n");
    
return a * b;
}


int _tmain(int argc, _TCHAR* argv[])
{
    
// 调用接口函数
    
// 可以根据需要调用不同的回调函数
    testCallback (callback);
    testCallback (callback2);
    
return 0;
}

在.net中,引入了“委托”的概念来代替回调函数的功能。这个概念很形象,客户程序“委托”一个中间人把处理结果告诉自己。另外,委托是完全面向对象的,更容易理解。