3 ms·
This is only related to the use of the this pointer. If you have a member of a class called s then any mention of s inside a member function of the class is re
by Negitivefrags 8y ago
This is only related to the use of the this pointer.
If you have a member of a class called s then any mention of s inside a member function of the class is really a mention of this->s.
After you understand that, you can just apply all the regular rules of lambdas to understand why it gets you in to trouble.
this->s is a capture of this, not s. this is a pointer and therefore capturing it by value isn't going to extend the lifetime of the object it points to.
- 0db532a0 8y agoI see from the below link that the ‘STAR this’ pointer would be captured implicitly by reference in this case. This happens regardless of a default capture type if it does exist. To truly capture a member by value, you can (1) make a copy of that value in the enclosing function, thus making it an automatic variable which can be value-captured, (2) value-capture through an initialiser in the capture list or (3) you can indicate ‘STAR this’ (since C++17) as a capture, which then captures the ‘this’ as a value copy and thus transitively your member. https://en.cppreference.com/w/cpp/language/lambda#Lambda_capture https://en.cppreference.com/w/cpp/language/lambda#Lambda_cap...