C ++的意义[] [英] C++ meaning of [ ]
本文介绍了C ++的意义[]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是从提升ASIO的一个例子。
这是什么意思?为什么[]?
acceptor_.async_accept(socket_,
[这](升压::系统::错误_ code EC)
解决方案
这是一个的拉姆达前pression 的用于创建一个函数作为前pression
[]
是捕捉列表
符号列表可以传递如下:
- [A,和b],其中一个是由价值和b捕获通过引用捕获
- [这]抓住this指针由值
- [&安培]捕获通过引用拉姆达的身体中提到的所有自动变量
- [=]捕获的价值由拉姆达的身体中提到的所有自动变量
- []捕捉什么
块引用>That's from an example of boosts asio. What does [this] mean? why the []?
acceptor_.async_accept(socket_, [this](boost::system::error_code ec)
解决方案It is a lambda expression used to create a function as an expression
[]
is the capture listA list of symbols can be passed as follows:
- [a,&b] where a is captured by value and b is captured by reference.
- [this] captures the this pointer by value
- [&] captures all automatic variables mentioned in the body of the lambda by reference
- [=] captures all automatic variables mentioned in the body of the lambda by value
- [] captures nothing
这篇关于C ++的意义[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文