Использование переменной-члена в списке захвата лямбды внутри функции-члена

Следующий код компилируется с gcc 4.5.1, но не с VS2010 SP1:

#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <set>
#include <algorithm>

using namespace std;
class puzzle
{
        vector<vector<int>> grid;
        map<int,set<int>> groups;
public:
        int member_function();
};

int puzzle::member_function()
{
        int i;
        for_each(groups.cbegin(),groups.cend(),[grid,&i](pair<int,set<int>> group){
                i++;
                cout<<i<<endl;
        });
}
int main()
{
        return 0;
}

Вот ошибка:

error C3480: 'puzzle::grid': a lambda capture variable must be from an enclosing function scope
warning C4573: the usage of 'puzzle::grid' requires the compiler to capture 'this' but the current default capture mode does not allow it

Итак,

1> какой компилятор правильный?

2> Как я могу использовать переменные-члены внутри лямбды в VS2010?

127
задан vivek 25 October 2011 в 21:05
поделиться