title: Nested lambda function
body: <p>I have the following code:</p>
  
  <pre><code>auto get_functor = [&amp;](const bool check) {
      return  [&amp;](const foo&amp; sr)-&gt;std::string {
          if(check){
              return "some string";
          }
          return "another string"
      };
  };
  run(get_functor(true));
  </code></pre>
  
  <p>The <code>run</code> function signature:</p>
  
  <pre><code>void run(std::function&lt;std::string(const foo&amp;)&gt; func);
  </code></pre>
  
  <p>I am getting the following error which is not so clear for me:</p>
  
  <blockquote>
  <pre><code>error C2440: 'return' : cannot convert from 'main::&lt;lambda_6dfbb1b8dd2e41e1b6346f813f9f01b5&gt;::()::&lt;lambda_59843813fe4576d583c9b2877d7a35a7&gt;' to 'std::string (__cdecl *)(const foo &amp;)'
  </code></pre>
  </blockquote>
  
  <p>P.S. I am on MSVS 2013</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>if I edit the code by replacing <code>auto</code> with the real type: </p>
  
  <pre><code>std::function&lt;std::string(const foo&amp;)&gt; get_functor1 = [&amp;](const bool check) {
      return  [&amp;](const foo&amp; sr)-&gt;std::string {
          if (check) {
              return "some string";
          }
          return "another string";
      };
  };
  run(get_functor1(true));
  </code></pre>
  
  <p>I am getting another error:</p>
  
  <blockquote>
  <pre><code>error C2664: 'std::string std::_Func_class&lt;_Ret,const foo &amp;&gt;::operator
  ()(const foo &amp;) const' : cannot convert argument 1 from 'bool' to
  'const foo &amp;'
  </code></pre>
  </blockquote>
  
  <p>Which is totally messed up!</p>