title: Registering a class member function as a callback to a function using std::bind
body: <p>I'm trying to register a class member function as a (regular) callback function. Unless I've misunderstood something, this should be possible using std::bind (using C++11). I do this the following way:</p>
  
  <pre><code>std::function&lt;void (GLFWwindow*, unsigned int)&gt; cb = std::bind(&amp;InputManager::charInputCallback, this, std::placeholders::_1, std::placeholders::_2);
  </code></pre>
  
  <p>My callback function is defined in the following way:</p>
  
  <pre><code>void InputManager::charInputCallback(GLFWwindow* window, unsigned int key)
  </code></pre>
  
  <p>I'm able to test <code>cb</code> immediately after creating using random data:</p>
  
  <pre><code>cb(NULL, 0x62);
  </code></pre>
  
  <p>I can confirm that this data is sent correctly to the callback function by printing to the terminal from within it. </p>
  
  <p>However, I want to register this function to GLFW so that the keypresses of the program window gets sent to the callback function. I do that like this:</p>
  
  <pre><code>glfwSetCharCallback(window, (GLFWcharfun) &amp;cb);
  </code></pre>
  
  <p>Like I said before: calling it manually works just fine. When I register it as a callback though, I get a segmentation fault whenever I press a key and GLFW tries to call the callback function.</p>
  
  <p>Is std::bind not what I'm looking for? Am I using it incorrectly?</p>
  
  <p>Edit: 
  I don't think this question is a duplicate of <a href="https://stackoverflow.com/questions/400257/how-can-i-pass-a-class-member-function-as-a-callback">How can I pass a class member function as a callback?</a> like it has been identified as. While we're adressing the same problem, I'm asking about this particular solution, using std::bind, which is only mentioned but never explained in one of the answers to the other question. </p>