Horde3D
http://horde3d.org/forums/

glfwSetKeyCallback with in a class?
http://horde3d.org/forums/viewtopic.php?f=2&t=627
Page 1 of 1

Author:  ulao [ 27.01.2009, 17:06 ]
Post subject:  glfwSetKeyCallback with in a class?

Hey all, Trying to organizer the basic ( re usable ) code in to a few classes and reached a snag here..

glfwSetKeyCallback( keyPressListener );

As most of you know. You are not necessarily permitted the passing of a member from with in a class. You will get..

error C3867: function call missing argument list; use '&CLASS::MEMBER' to create a pointer to member

So I tried to pass the address of the member or using a pointer to the function, I even tried the sloppy global approach. No matter what I try I get errors. Has anyone used this call in a function?

Author:  swiftcoder [ 27.01.2009, 17:10 ]
Post subject:  Re: glfwSetKeyCallback with in a class?

ulao wrote:
glfwSetKeyCallback( keyPressListener );

As most of you know. You are not necessarily permitted the passing of a member from with in a class. You will get..

error C3867: function call missing argument list; use '&CLASS::MEMBER' to create a pointer to member
You cannot pass an instance function where a free function is required. You can either use free (global) functions for your callbacks, as the samples do, or you can use static class methods.

Author:  ulao [ 27.01.2009, 17:44 ]
Post subject:  Re: glfwSetKeyCallback with in a class?

I used static but get "error LNK2001: unresolved external symbol " during linking?

Author:  Volker [ 27.01.2009, 17:54 ]
Post subject:  Re: glfwSetKeyCallback with in a class?

You have to implement that function

Author:  ulao [ 27.01.2009, 17:57 ]
Post subject:  Re: glfwSetKeyCallback with in a class?

durr, thx ;)

Author:  DarkAngel [ 28.01.2009, 02:51 ]
Post subject:  Re: glfwSetKeyCallback with in a class?

I used a global pointer (singleton kind-of design) when I made my GLFW wrapper class:

Header:
Code:
class CApp
{
public:
   CApp();
   virtual void KeyStateChange( int key, bool down );///< Callback to respond to keyboard state changes
};
extern CApp* g_pApp;


Source file:
Code:
CApp* g_pApp = 0;
CApp::CApp()
{
   g_pApp = this;
}

void GLFWCALL MyKeyCallback( int k, int action )
{
   if( !g_pApp )
      return;
   g_pApp->KeyStateChange( k, (action==GLFW_PRESS) );
}


And then inside the initialisation function:
Code:
      glfwSetKeyCallback( &MyKeyCallback );

Author:  ecksp [ 28.01.2009, 07:03 ]
Post subject:  Re: glfwSetKeyCallback with in a class?

Using something like SFML is also a nice option that let's you sidestep this problem altogether :)

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/