title: Strange behaviour of passing out refernce in binding of lambda function
body: <p>I want to pass out some parameter from the lambda function, so I bind a reference parameter to a lambda function. However, the outer variable is not changed after calling the function. If I bind the lambda function with the pointer of outer variable, the result is correct. </p>
  
  <p>I show the test program as follows and want to know why the outer variable does not change, given that I have already defined the pass-by-reference lambda function <code>[&amp;]</code>? </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  #include &lt;functional&gt;
  
  using namespace std;
  
  int main(int argc, char* argv[])
  {
      string acc_ref, acc_ptr;
      //  define function via reference
      auto fProcRefEx = [&amp;](string&amp; acc, const string&amp; s) -&gt; void
      {
          acc += s;
      };
      auto fProcRef = bind(fProcRefEx, acc_ref, placeholders::_1);
      //  define function via pointer
      auto fProcPtrEx = [&amp;](string* pacc, const string&amp; s) -&gt; void
      {
          (*pacc) += s;
      };
      auto fProcPtr = bind(fProcPtrEx, &amp;acc_ptr, placeholders::_1);
      //  test
      vector&lt;string&gt; v = {"abc", "def"};
      for_each(v.begin(), v.end(), fProcRef);
      cout &lt;&lt; "acc_ref: " &lt;&lt; acc_ref &lt;&lt; endl;  //  acc_ref is empty, wrong
      for_each(v.begin(), v.end(), fProcPtr);
      cout &lt;&lt; "acc_ptr: " &lt;&lt; acc_ptr &lt;&lt; endl;  //  acc_ptr is "abcdef", correct
      return 0;
  }
  </code></pre>