title: Using member variable in lambda capture list inside a member function
body: <p>The following code compiles with gcc 4.5.1 but not with VS2010 SP1:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;map&gt;
  #include &lt;utility&gt;
  #include &lt;set&gt;
  #include &lt;algorithm&gt;
  
  using namespace std;
  class puzzle
  {
          vector&lt;vector&lt;int&gt;&gt; grid;
          map&lt;int,set&lt;int&gt;&gt; groups;
  public:
          int member_function();
  };
  
  int puzzle::member_function()
  {
          int i;
          for_each(groups.cbegin(),groups.cend(),[grid,&amp;i](pair&lt;int,set&lt;int&gt;&gt; group){
                  i++;
                  cout&lt;&lt;i&lt;&lt;endl;
          });
  }
  int main()
  {
          return 0;
  }
  </code></pre>
  
  <p>This is the error:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>So,</p>
  
  <p>1> which compiler is right?</p>
  
  <p>2> How can I use member variables inside a lambda in VS2010?</p>