Jump to content
  • Advertisement
Sign in to follow this  
moetman

Boost::bind help

This topic is 4768 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering if someone could help me with this : I have a class member function void GLFWCALL Display::processKeys( int key, int action ) I wish to assign this to a callback in main() using boost::bind so glfwSetKeyCallback( processKeys ); will become glfwSetKeyCallback( boost::bind(&Display::processKeys ) ); my intention being to use member functions as function arguments to callback functions, however I'm unsure wether I should be using boost::bind or boost::mem_fn or both ? and I'm unsure about the argument parameter list to boost::bind. Kind Regards Paul

Share this post


Link to post
Share on other sites
Advertisement
When you pass it a member function, boost::bind also includes the 'this' object in the parameter list, so here, boost::bind would expect a total of four parameters: the member function pointer, the object, and the two function parameters. If you want the callback to use a specific object, you'll have to pass it to boost::bind like so: boost::bind(&Display::processKeys, DisplayObjectOrPointer, _1, _2) which will yield a two-parameter function object. If you want to leave that parameter open, you can do boost::bind(&Display::processKeys, _1, _2, _3) or boost::mem_fn(&Display::processKeys), which will yield a 3 parameters function object.

Unfortunately, I do not know if glfwSetKeyCallback is designed to accept a boost::function parameter rather than a function pointer, sorry.

Share this post


Link to post
Share on other sites
Thanks Fruny ,
I don't think the boost libraries can help me .There must be some library out there that will let you access class member functions to use as arguments to callback functions that contain a specific parameter list ..like in glfwSetKeyCallback: void (*) (int,int)

Share this post


Link to post
Share on other sites
afaik not if the function only expects a normal function call, because extra infomation needs to travel with it to enable it to work.

Meh.. I should really get the linux port of my <pimp>OpenGL Window Framework</pimp> done and key processing added as that will let you do what you want as it uses boost::function objects as call backs [grin] (what can I say, I'm a C++ monkey)

edit: or what Fruny said [grin]

Share this post


Link to post
Share on other sites
cool [grin]

Let me know (via email or PM) if you need any extra window message types added to it, its only a matter of moments work todo so [smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!