title: Lambdas and capture by reference local variables : Accessing after the scope
body: <p>I am passing my local-variables by reference to two lambda. I call these lambdas outside of the function scope. Is this <code>undefined</code> ?</p>
  
  <pre><code>std::pair&lt;std::function&lt;int()&gt;, std::function&lt;int()&gt;&gt; addSome() {
      int a = 0, b = 0;
      return std::make_pair([&amp;a,&amp;b] {
          ++a; ++b;
          return a+b;
          }, [&amp;a, &amp;b] {
              return a;
          });
  }
  
  int main() {
      auto f = addSome();
      std::cout &lt;&lt; f.first() &lt;&lt; " " &lt;&lt; f.second();
      return 0;
  }
  </code></pre>
  
  <p>If it is not, however, changes in one lambda are not reflected in other lambda.</p>
  
  <p>Am i misunderstanding pass-by-reference in context of lambdas ?</p>
  
  <p>I am writing to the variables and it seems to be working fine with no runtime-errors with output</p>
  
  <p><code>2 0</code>. If it works then i would expect output <code>2 1</code>.</p>