c++ 中是否有等同于目标 c 中的"block"的功能?
Is there a feature in c++ that equivalent to the "block" in objective c?
正如标题所说。c++中是否有与目标c中的"块"等效的特征?谢谢
lambdas?
[&](){
printf("Hello!");
}
是的,您可以在c++11中使用std::function(lambda函数)。这些函数的工作原理与目标c 中的块类似
定义
typedef std::function<void(std::string message, bool status)> LoginCallback
使用类内函数
void loginUser(std::string email, std::string password, LoginCallback loginCallback)
假设上述函数在LoginClass 中
函数调用
loginClassObj.loginUser("abc@xyz.com", "password", [this](std::string message, bool status){//Callback will received here});
它是C的非标准扩展。它是lambda函数的闭包,基本上它们是类似于未命名函数的实体,包含了可以调用的代码。例如,它们有助于编写事件驱动的代码,在这些代码中,回调被详尽地使用。请参阅此
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 多态性和功能结合
- 带内存和隔离功能的SQLite
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- 类模板的成员功能的定义在单独的TU中完全专业化
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 如何在C++中获得"静态纯虚拟"功能?
- 两个文件使用彼此的功能-如何解决
- 我应该实现右值推送功能吗?我应该使用std::move吗
- QML按钮点击功能执行顺序
- 无法理解此 return 语句的功能,没有它就会发生运行时错误
- 有没有可能有一个只有ADL才能找到的非好友功能
- 功能样式转换从 'int' 到 'ItemType' 的匹配转换
- 文件系统:复制功能的速度秘诀是什么
- 在用于格式4的arm模拟器中实现功能时的一个问题
- 如何在Directwrite中获得给定字体的可用OpenType功能
- 对可变参数使用声明.如何选择正确的功能
- 询问在设计我的手臂模拟器功能表示格式1
- 功能原型的目的
- c++ 中是否有等同于目标 c 中的"block"的功能?