Callback Member Functions

anonymous wrote on Saturday, May 15, 2004:

I tried to make a member function of one of my classes into a callback function, but it gave me an error. Is there a way to have a callback member function?

cozman wrote on Monday, May 17, 2004:

Make the member function a static member function & it should work.

anonymous wrote on Monday, May 17, 2004:

That will work currently. But in the future I may decide to have multiple instantiations of this class. In that case, I will want to be able to control which object’s member function is set as the callback function.

Also I don’t like static members because they are too global…

anonymous wrote on Monday, May 17, 2004:

That will work currently. But in the future I may decide to have multiple instantiations of this class. In that case, I will want to be able to control which object’s member function is set as the callback function.

Also I don’t like static members because they are too global compared to non-static members. I don’t need or want my callback functions to be that global.

nobody wrote on Tuesday, May 18, 2004:

Look into functors, it allows you to link a callback function to any member function.

the_speed_bump wrote on Thursday, May 20, 2004:

I would like to see this supported as well.

All that’s really required is that every callback have accompanying user data that’s big enough for a pointer.  From there, it’s easy enough to write a C stub that relays to the proper method.

marcus256 wrote on Friday, May 21, 2004:

Hi! This [user data in callbacks] is actually a planned feature. It may not appear anytime soon since it would wreck the 2.x API, but I realize that it’s an important feature, especially when/if support for multiple windows appear (you may want to use the same callback for multiple windows).