C++ lambda capture this vs capture by reference

后端 未结 4 844
误落风尘
误落风尘 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:06

    Capturing this and capturing by reference are two orthogonal concepts. You can use one, both, or none. It doesn't make sense to capture this by reference but you can capture other variables by reference while capturing this by value.

提交回复
热议问题