比如在C库里实现了一个算法叫做快速排序(qsort),为了能让库更加通用,不想在函数中嵌入排序逻辑,而让使用者来实现相应的逻辑,这时就可以使用回调函数方式来实现。
基于247个网页-相关网页
You could use a typedef to define a callback and make clients supply it, something similar to qsort-but that's so old-hat.
你可以用typedef来定义一个回调并让客户机来提供这个回调,这种做法有些类似qsort——但那样太老土了。
Many STL containers let you play the same trick. Most programmers wouldn't call the qsort callback an event, but there's no reason you can't think of it that way.
借助许多 STL 容器也能实现同样的诀窍.大多数程序员不会调用 qsort 回调某个事件,但你没有理由不考虑那种方式。
To Invoke an Application-Supplied Algorithm The C runtime library function qsort sorts an array of objects, but you must supply the function that compares objects.
调用应用程序提供的算法:C 运行时库函数 qsort 排序对象数组,但你必须提供比较函数。
应用推荐