What is a block in C++? [duplicate]

痴心易碎 提交于 2019-12-08 02:00:59

问题


Possible Duplicate:
What is (double (^)(int))foofoo

I've tried searching for a definition on Google and SO and I found examples in which they are used but not clearly defined. By "block" I mean the caret symbol (^). I found it on a site where cdecl they described:

(double (^)(int, long long )) foo

as

cast foo into block(int, long long) returning double

I've never once seen this symbol used before today. Can anyone clearly describe what a block is and include with it a minimal working example? Thanks.


回答1:


Blocks are a non-standard extension to the C (and not only to the Objective-C) language by Apple. They realize closures (lambda functions, etc., however you call them) - basically they're unnamed function-like entities, enclosing code that can be called. They facilitate writing for example event-driven code, where callbacks are used exhaustively.



来源:https://stackoverflow.com/questions/12270079/what-is-a-block-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!