Advertisement Jump to content


This topic is now archived and is closed to further replies.


callback functions driving me nuts!!

This topic is 5466 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

hi!, i''ve been searching all over the net and i couldn''t find A THING about how to implement callback functions. i want to make a callback member function on my class, but i don''t know how to do it (i wanna make a timer class that handles the events by itself) so can you help me?? HOW DO I IMPLEMENT A CALLBACK FUNCTION?? thanks in advance

Share this post

Link to post
Share on other sites
I think that class member can not be a CALLBACK function.
But i''am not 100%sure :D

"The Gods Made Heavy Metal And They Saw That It Was Good They Said To Play It Louder Than Hell We Promised That We Would
When Losers Say Its Over With You Know That It’s A Lie The Gods Made Heavy Metal And It’s Never Gonna Die"


Share this post

Link to post
Share on other sites

Class memebers may be callbacks, check out the other threads on this topic.

Share this post

Link to post
Share on other sites
Assuming that you, like the hundreds of posters before you who asked the very same question (without bothering to do a forum search), want to use a non-static member function as callback, here is the minimum code to "make it work" - that is, how to make a call via a pointer to member. Pointers to static members really are just the same as pointers to non-members.

class Foo
int bar(int);

int (Foo::*mfptr)(int);
mfptr = &Foo::bar;

Foo obj;
Foo* ptr = new Foo;


The callback API will have to be designed specifically to accept pointers to Foo members, not just ordinary pointers. If it hasn't (e.g. Win32 API), it is simply impossible to make it work in C++.

You will also have to pass the pointer and the object separately to your callback API and let it rejoin them at the last moment. The expression obj.*mfptr is known as a bound pointer to member and cannot be manipulated in any other way but immediately calling it. No assigment to a variable, no passing to a function, no nothing.

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)

[edited by - Fruny on February 6, 2004 3:38:09 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!