http://coliru.stacked-crooked.com/a/29520ad225ced72dलैम्बडा में सदस्य चर को संशोधित करने के लिए [=] का उपयोग क्यों किया जा सकता है?
#include <iostream>
struct S
{
void f()
{
//auto f0 = [] { ++i; }; // error: 'this' was not captured for this lambda function
auto f1 = [this] { ++i; };
auto f2 = [&] { ++i; };
auto f3 = [=] { ++i; };
f1();
f2();
f3();
}
int i = 10;
};
int main()
{
S s;
std::cout << "Before " << s.i << std::endl;
s.f();
std::cout << "After " << s.i << std::endl;
}
Before 10
After 13
प्रश्न: क्यों [=]
एक लैम्ब्डा में सदस्य चर के संशोधन सक्षम है?
'odr-used' का अर्थ क्या है? – q0987
@ q0987 http://stackoverflow.com/questions/19630570/what-does-it-mean-to-odr-use-something – user2176127
इसके बारे में सोचें कि यह 'मूल्य' मूल्य के आधार पर है। – Yakk