<分区>
这是来自 boosts asio 的一个例子。 这是什么意思?为什么是 []?
acceptor_.async_accept(socket_,
[this](boost::system::error_code ec)
标签 c++ boost boost-asio
<分区>
这是来自 boosts asio 的一个例子。 这是什么意思?为什么是 []?
acceptor_.async_accept(socket_,
[this](boost::system::error_code ec)
最佳答案
这是一个lambda expression用于创建作为表达式的函数
[]
是捕获列表
A 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++含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22327248/