回调函数和普通函数的区别
我用谷歌搜索了很多来找出普通函数和回调函数之间的区别。不幸的是我无法理解。如果我们必须在另一个函数中调用一个函数,那么使用函数指针将其作为参数传递给该函数有什么用处? 是否可以在函数外部的某个地方以函数指针的形式调用作为参数传递的函数,在该函数中作为参数传递的函数?如果是,请告诉我其实施的大概情况。 谢谢
i have googled a lot to find out the difference between normal function and callback function. Unfortunatley I could not understand. if we have to call a function inside another function, what is usefulness of passing it as a parameter to the function by using function pointers?
Is it possible to call the function passed as a parameter in the form of function pointers somewhere outside the function, in which it is passed as parameter? if yes, please give me a rough idea of its implementation.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您有一个功能需要执行一些长时间操作,例如发送电子邮件。您不想等待它完成,因此您给它一个回调函数,该函数将在完成后调用。这是回调的主要用途——异步操作的通知。还有其他用途。
Say you have a function that does some prolonged operation, like send email. You don't want to wait for it to finish, so you give it a callback function that will invoke once it's done. That's a major use of callbacks - notification of asynchronous operations. There are other uses.