title: C++11 lambdas to Function Pointer
body: <p>I'm starting to develop applications using C++11 lambdas, and need to convert some types to function pointers. This works perfectly in GCC 4.6.0:</p>
  
  <pre><code>void (* test)() = []()
  {
      puts("Test!");
  };
  
  test();
  </code></pre>
  
  <p>My problem is when I need to use function or method local variables within the lambda:</p>
  
  <pre><code>const char * text = "test!";
  
  void (* test)() = [&amp;]()
  {
      puts(text);
  };
  
  test();
  </code></pre>
  
  <p>G++ 4.6.0 gives the cast error code:</p>
  
  <pre><code>main.cpp: In function 'void init(int)':
  main.cpp:10:2: error: cannot convert 'main(int argc, char ** argv)::&lt;lambda()&gt;' to 'void (*)()' in initialization
  </code></pre>
  
  <p>If use <strong>auto</strong>, it works ok:</p>
  
  <pre><code>const char * text = "Test!";
  
  auto test = [&amp;]()
  {
      puts(text);
  };
  
  test();
  </code></pre>
  
  <p>My question is: how can I create a type for a lambda with <strong>[&amp;]</strong>? In my case, I can not use the STL <strong>std::function</strong> (because my program does not use C++ RTTI and EXCEPTIONS runtime), and It has a simple implementation of function to solve this problem?</p>