jeudi 19 mars 2015

C++ lambda capture - which get's captured?


So I have the expression below inside a class, following definitions:



std::vector<std::function<MyClass (const MyClass&)>> funcVec;
result->funcVec.push_back([=](const MyClass& child){
return this->funcVec[i](child);
});


(E.g. copy the lambda evaluation of (this) to the result instance)


The qustion is that I'm not sure which is captured by value - the whole object (this),potentially i or just the function (ths->funcVec[i])?


Any extra explanations and recommendation of why not to use this make it better, or confirmation that this is ok are more than welcome.




Aucun commentaire:

Enregistrer un commentaire