C++ lambda capture this vs capture by reference

后端 未结 4 868
误落风尘
误落风尘 2021-01-03 19:33

If I need to generate a lambda that calls a member function, should I capture by reference or capture \'this\'? My understanding is that \'&\' captures only the variable

4条回答
  •  独厮守ぢ
    2021-01-03 20:21

    Here is a good explanation of what &, this and the others indicate when used in the capture list.

    In your case, assuming that all what you have to do is calling a member function of the instance that is actually referenced by the this of the method that is currently executing, put this in your capture list should be enough.

提交回复
热议问题