title: To pass a pointer to a member function
body: <p>I have an class with instance functions (or methods?). From within an instance, I try to pass pointers to those functions to a library.  The library expects static functions.</p>
  
  <p>When I pass my pointers to the callback functions, the compiler complains that my functions are not static. I tried to put make them static, but if I do so, then I can't access the instance fields from within the functions.</p>
  
  <p>How could I go around this?</p>
  
  <p>Similar question is : <a href="https://stackoverflow.com/questions/1000663/using-a-c-class-member-function-as-a-c-callback-function">Using a C++ class member function as a C callback function</a> where they suggest to put the method static.  However I can't do that, or I don't see how I could.</p>
  
  <h1>Code</h1>
  
  <pre><code>GlutController::GlutController (int argc, char **argv) {
  
     // stuff ..
  
     // Register callbacks
     glutSpecialFunc( OnSpecialKeys );  // Error, need static functions
     glutReshapeFunc( OnChangeSize );   // Error...
     glutDisplayFunc( OnRenderScene );  // Error...
  
     // stuff ..
  }
  
  GlutController::~GlutController() {
  
  }
  
  void GlutController::OnChangeSize(int aNewWidth, int aNewHeight){
  
     glViewport(0,0,aNewWidth, aNewHeight);
     mViewFrustrum.SetPerspective( APP_CAMERA_FOV,             // If this function is 
              float( aNewWidth ) / float( aNewHeight ),        // static, this won't 
              APP_CAMERA_NEAR,                                 // work
              APP_CAMERA_FAR );
     mProjectionMatrixStack.LoadMatrix(                        // Same here
              mViewFrustrum.GetProjectionMatrix() );
     mTransformPipeline.SetMatrixStacks(mModelViewMatrixStack, // Same here  
              mProjectionMatrixStack);
  
  }
  
  void GlutController::OnRenderScene(void){
     mGeometryContainer.draw();                                // Won't work if static
  }
  
  void GlutController::OnSpecialKeys(int key, int x, int y){
     mGeometryContainer.updateKeys(key);                       // Won't work if static
  }
  </code></pre>
  
  <p><em>Disclaimer : I just begun C++.  I read all of Accelerated C++ and this is my first project to try out the language.  My background is in Java.</em></p>