For example:
class Example { public: explicit Example(int n) : num(n) {} void addAndPrint(vector<int>& v) const { for_each(v.begin(), v.end(), [num](int n) { cout << num + n << " "; }); } private: int num; }; int main() { vector<int> v = { 0, 1, 2, 3, 4 }; Example ex(1); ex.addAndPrint(v); return 0; }
When you compile and run it in MSVC2010, you get the following error:
error C3480: 'Example :: num': lambda capture variable must be from the application area
However, with g ++ 4.6.2 (preerelease) you get:
1 2 3 4 5
Which compiler is right according to the standard draft?
Jesse good
source share