Below lines of code give error:
std::vector<std::string> strVect;
auto pushToVector = [strVect] () {
strVect.push_back(std::string("Hi"));
};
pushToVector ();
ERROR:
2 overloads have no legal conversion for 'this' pointer
But when I pass strVect
by reference in lambda there is no error.
std::vector<std::string> strVect;
auto pushToVector = [&strVect] () {
strVect.push_back(std::string("Hi"));
};
pushToVector ();
NO ERROR
Please let me know why do we get error in fist scenario?
Aucun commentaire:
Enregistrer un commentaire