restriction about default capture mode and 'this' in C++ lambda-expression

前端 未结 1 845
有刺的猬
有刺的猬 2021-02-05 19:56

I\'m wondering why = capture-default mode prohibits this in capture-list of C++ lambda expression.

That is,

相关标签:
1条回答
  • 2021-02-05 20:22

    this can only be captured by copy and never by reference. Even if you specify only [&], this can be implicitly captured by copy if odr-used. Therefore, [=, this] is an error because = would already implicitly capture this by copy while the & in [&, this] signifies capture by reference and does not implicitly capture this (unless it is odr-used)

    0 讨论(0)
提交回复
热议问题