Jump to content
  • Advertisement
Sign in to follow this  
Misery

Pointer to function returning void

This topic is 2518 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 there,

I am trying to make a function taking as one argument another function. This passed function is of type:


void SomeFunc(int blabla)
{
//do something
}



How do I define properly this function to which I pass the mentioned one? Is this fine?

SomeRetValuetype Func( void (AFunction(int)) )
{
//do some stuff
AFunction(someintvalue);
//do some stuff
}


Is the example from above ok?
When I made this argument passing the way defined for other functions (as I did usually) I get a bunch of errors:

SomeRetValuetype Func( void (*AFunction(int)) )
{
//do some stuff
AFunction(someintvalue);
//do some stuff
}


on GCC:

error: invalid conversion from 'void (*)(void*) {aka void (*)(void*)}' to 'void* (*)(void*)' [-fpermissive]|

Thanks in advance for any suggestions,
Misery

Share this post


Link to post
Share on other sites
Advertisement
its easier if you use a typedef:

typedef void (*myfunc_t)(int);

SomeRetValuetype Func( myfunc_t fp )
{
fp(1);
}


or if you want to do it inline:


SomeRetValuetype Func( void (*fp)(int) )
{
fp(1);
}

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.

GameDev.net 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!