Jump to content
  • Advertisement


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


Pointers to Functions..Callback?

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

Hello all, How do I go about making a function that I can pass a pointer to of another function. I think this kind of thing is called callback functions. I dunno though. The kind of function I am trying to create would be something like the ''CreateThread" fuction, where you have to pass a pointer to a function that later will be called. How do I go about writing a function like this? So far I have: //------------CODE------------ typedef void (*Function)(); Function myFunction; void runFunction(Function pFunction){ myFunction = pFunction; (myFunction)(); } void TheFunctionToRun(){ ShowMessage("Hello"); } void main(){ runFunction(&TheFunctionToRun); } //---------------------------- I know i should simply fun "pFunction" streight away instead of assigning it to a variable, But that is part of the requirement of the function. That code does not work, and I''m not suprised as I have never tried to do anything like this before. Can anyone enlighten me as to how I should fix this problem? BTW, I have seen posts in these forums with sections that have sections for code, and there is syntax highlighting. How do I do this?

Share this post

Link to post
Share on other sites
well, the code works for me, it would help if you told us what problems you are having (error messages please)

more info about function pointers: www.function-pointer.org

read about formatting in the forum faq

Edited by - kvh on December 30, 2001 9:43:32 AM

Share this post

Link to post
Share on other sites
Sorry about that, I didn''t expect the code to be right, I thought the problem would be obvious as I have never done this before and was bound to make mistakes.

Anyways, the error that the compiler gives is...
Member function must be called or it''s address taken.

I just realised what was causing this error though, I had "()" after the definition of the "MyFunction" variable.

Sorry to have wasted your time

Share this post

Link to post
Share on other sites

  • 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!