什么是C ++中的块? [英] What is a block in C++?

查看:155
本文介绍了什么是C ++中的块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

什么是(double(^)(int))foofoo

我试着在Google和SO上搜索一个定义,我发现了使用它们但没有明确定义的例子。 块我的意思是插入符号( ^ )。我发现它 on

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


cast foo into block(int,long long)返回double

ve从来没有一次看到这个符号在今天之前使用。任何人都可以清楚地描述一个块是什么,并包括它一个最小的工作示例?感谢。

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.

推荐答案

Blocks 是Apple的C(而不仅仅是Objective-C)语言的非标准扩展。他们实现了闭包(lambda函数等,但是你称之为它们) - 基本上它们是未命名的函数式实体,包含可以调用的代码。它们有助于编写例如事件驱动代码,其中回调被穷尽地使用。

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.

这篇关于什么是C ++中的块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆