C++ meaning of [ ] [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 17:51:42

问题


That's from an example of boosts asio. What does [this] mean? why the []?

acceptor_.async_accept(socket_,
    [this](boost::system::error_code ec)

回答1:


It is a lambda expression used to create a function as an expression

[] is the capture list

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



回答2:


It is a part of a lambda expression. Look here for more info.



来源:https://stackoverflow.com/questions/22327248/c-meaning-of

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