Undefined Behavior with the C++0x Closure: I
问题 Consider the example: #include <iostream> #include <functional> // std::function #include <vector> // std::vector #include <algorithm> // std::for_each int main(){ auto adder = [](int x) { return [&](int y) { return x+=y; }; }; std::vector < std::function<int(int)> > vec; vec.push_back(adder(1)); vec.push_back(adder(10)); std::for_each(vec.begin(), vec.end(), [](std::function<int(int)> f){std::cout << f(33) << " ";}); std::cout << std::endl; } One expects the integers 34 and 43 43 and 76 ,