title: Use lambda as GLFWkeyfun
body: <p>For one of my project, I am using GLFW3. And I am trying to give a C++11 lambda to the function <a href="http://www.glfw.org/docs/latest/group__input.html#ga7e496507126f35ea72f01b2e6ef6d155" rel="nofollow noreferrer">GLFWSetKeyCallback</a>, who takes as parameters a GFLWwindow, and a GLFWfunkey function, which is a typedef to
  void(* GLFWkeyfun) (GLFWwindow *, int, int, int, int).</p>
  <p>The function is called from my Window class, here's the code</p>
  <p>window.hpp</p>
  <pre><code>class Window
  {
          public:
                  Window(GLuint width, GLuint height, std::string title);
                  ~Window();
  
                  GLFWwindow* get() { return window_.get(); }
                  bool is_open() { return open_; };
                  void close();
  
          private:
                  bool open_ = false;
                  std::unique_ptr&lt;GLFWwindow, DestroyWindow&gt; window_;
                  std::vector&lt;Drawable*&gt; drawables_;
  };
  </code></pre>
  <p>And window.cpp</p>
  <pre><code>#include &lt;pck/window.hpp&gt;
  
  Window::Window(GLuint width, GLuint height, std::string title) :
          open_(true)
  {
          window_.reset(glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr));
      glfwMakeContextCurrent(window_.get());
  
          Global::width = width;
          Global::height = height;
  
          glfwSetKeyCallback(window_.get(), [this](GLFWwindow* window, int key, int scancode, int action, int mode){
                  for(auto it : drawables_)
                          it-&gt;input(window, key, scancode, action, mode);
          });
  }
  
  Window::~Window()
  {
          window_.reset();
  }
  
  void
  Window::close()
  {
          open_ = false;
          window_.reset();
  }
  </code></pre>
  <p>And the error from the compiler (clang++ 3.8.1)</p>
  <pre><code>fatal error: no matching function for call to 'glfwSetKeyCallback'
          glfwSetKeyCallback(window_.get(), [this](GLFWwindow* window, i...
          ^~~~~~~~~~~~~~~~~~
  /usr/include/GLFW/glfw3.h:3307:20: note: candidate function not viable: no
        known conversion from '(lambda at
        /path/to/file.cpp)' to
        'GLFWkeyfun' (aka 'void (*)(GLFWwindow *, int, int, int, int)') for 2nd argument
  GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow* window, GLFWkeyfun cbfun);
  </code></pre>
  <p>Can somebody point me to what I did wrong please?</p>
  <p>Thanks!</p>