below is my practice code about c++11 lambda:
#include<iostream>
int d = 0;
int main()
{
int e = 1;
auto i = [&]() ->int {
e += 1;
d += 1;
return d;};
d += 1;
std::cout << "the value of d:" << d << std::endl;
std::cout << "the value of i():" << i() << std::endl << " e:" << e << " d:" << d << std::endl;
std::cout << " e:" << e << " d:" << d << std::endl;
return 0;
}
and i got result not as expected:
the value of d:1
the value of i():2
e:1 d:1
e:2 d:2
I just don't understand why
std::cout << "the value of i():" << i() << std::endl << " e:" << e << " d:" << d << std::endl;
std::cout << " e:" << e << " d:" << d << std::endl;
this two lines give different out put of e and d?
ps:forgive my bad english