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

推荐订阅源

T
The Blog of Author Tim Ferriss
S
Securelist
D
Docker
The Register - Security
The Register - Security
GbyAI
GbyAI
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
罗磊的独立博客
博客园 - 【当耐特】
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
I
InfoQ
MyScale Blog
MyScale Blog
量子位
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
The Hacker News
The Hacker News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
博客园_首页
H
Help Net Security
K
Kaspersky official blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
The Cloudflare Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
爱范儿
爱范儿
P
Privacy International News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog RSS Feed

博客园 - 火鸟

一点想法 无 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中,引入了“委托”的概念来代替回调函数的功能。这个概念很形象,客户程序“委托”一个中间人把处理结果告诉自己。另外,委托是完全面向对象的,更容易理解。