Sign in to follow this  
yanco

Error C2664 ...

Recommended Posts

yanco    126
Hello Everybody! I'm having problems with compilation of my project under MSVC-2003. I'm getting this error: error C2664: 'glfwSetKeyCallback' : cannot convert parameter 1 from 'void (int,int)' to 'GLFWkeyfun' None of the functions with this name in scope match the target type The error is in main() when trying to bind my callback function...
int main(void) {
 ...
  glfwSetKeyCallback( input.KeyRoutine );//error C2664
 ...
}
This the function in my class InputHandler (inpurhadler.h)
  void GLFWCALL InputHandler::KeyRoutine(int key, int action);
and this is definition in glfw.h file I'm using ..
  typedef void (GLFWCALL * GLFWkeyfun)(int,int);  

  GLFWAPI void GLFWAPIENTRY glfwSetKeyCallback( GLFWkeyfun cbfun ); 
When I use normal C function like void KeyRoutine(int a, int b); it works perfectly, but not with member function of my InputHandler class.. Could anybody please help me with this? I would really appreciate it.Thank you very much. yanco.

Share this post


Link to post
Share on other sites
tj963    234
Member functions and normal functions are different and so are pointers to them. You'll either have to make the member function static or use a regular function, and then call into the class function if you really need to.

tj963

Share this post


Link to post
Share on other sites
yanco    126
Making it static helps of course, but I can't use it (function is working with non-static members). If there's no other way, I would use the second choice, but isn't there really any other way around this problem??

Thank you for your answers!
yanco

Share this post


Link to post
Share on other sites
jeroenb    282
No, there is no other way to do this. It's either a static member function or another function. It is however possible to call non-static functions from a static function by passing it somehow a pointer to the original class object. When this InputHandler class is a singleton, that is even easier to accomplisch.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this