lambda expression (MSVC++ vs g++)
问题 I have the following code #include <algorithm> #include <iostream> #include <vector> #include <functional> int main() { typedef std::vector<int> Vector; int sum=0; Vector v; for(int i=1;i<=10;++i) v.push_back(i); std::tr1::function<double()> l=[&]()->double{ std::for_each(v.begin(),v.end(),[&](int n){sum += n; //Error Here in MSVC++}); return sum; }; std::cout<<l(); std::cin.get(); } The above code produces an error on MSVC++ 10 whereas it compiles fine with g++ 4.5 . The error produced is 1