title: Callback function inside class
body: <p>I am trying to create a window container for sfml windows. If you are not familiar with sfml, a sfml window is a class which is non-copyable so cannot be put inside a std::vector for example.</p>
  
  <p>I've done most of the work, but I am now trying to implement some sort of callback function which will do the open-gl drawing work before window.Display() is called to update the window.</p>
  
  <p>I cannot get my head around the syntax of a callback function (either c or c++ version). Would someone be willing to explain an example to me?</p>
  
  <p>Even better, would someone be willing to explain an example of how to implement a callback function in a class, so that a function (which the user defines) can be passed into a function of the class which will remember what that function was so it can be called by the class later.</p>
  
  <p>To make that above sentence clearer: I think there are three things I need:</p>
  
  <p>1): A function which the user defines, for example:</p>
  
  <pre><code>void doDrawing(){
      // do some open gl stuff
  }
  </code></pre>
  
  <p>2:) A function inside a class which takes the argument of the above, user defined function:</p>
  
  <pre><code>void setDisplayFunc( ?argument of a function? argument ){
      function_pointer pointer = argument;
  }
  </code></pre>
  
  <p>I have no idea what the type of 'argument' should be, or what 'function_pointer' has to be... I think this is where I am most stuck!</p>
  
  <p>3:) A way in which the class can call the function which was assigned above.</p>
  
  <pre><code>// Do the function which is pointed at by pointer, which is of the type 'function_pointer' ... Whatever function_pointer happens to be!
  </code></pre>
  
  <p>If anyone has used glut before, then I guess I am trying to implement the glut callback functions which look like:</p>
  
  <pre><code>void someDisplayFunction(){
      // do open gl stuff
  }
  
  glutDisplayFunc( someDisplayFunction );
  </code></pre>
  
  <p>The above function takes the argument of a user-defined function and then does it when we call 'glutPostRedisplay' ...</p>
  
  <p>I hope this makes sense, I have tried to include as much information as I can to help. Any help is appreciated. (:</p>