Page 1 of 1

[SOLVED] Question about functions

Posted: Tue Apr 13, 2010 2:31 pm
by xiphirx
I have a few functions that act like buttons, and I was wondering if there was a way to make a general function, and somehow pass a function to a function? lol

like, I could say
void drawButton(SDL_Surface* destination, SDL_Surface* source, int x, int y, SDL_Event &event, FUNCTION HERE);

and say
drawButton(screen, image, 10, 10, events, rotateMap(90));

If I am going about this wrong, then you can yell at me about that too D:

Re: Question about functions

Posted: Tue Apr 13, 2010 2:47 pm
by hurstshifter
I'm not 100% sure about what you are looking to accomplish but for this example that you listed...
xiphirx wrote:drawButton(screen, image, 10, 10, events, rotateMap(90));
That would be passing the return value of the rotatemap() function as an argument to the drawButton() function. So if rotatemap(90) returns a boolean 'true' for example, it would be passing 'true' into the drawButton function. Although this may not be what you are looking for.

Re: Question about functions

Posted: Tue Apr 13, 2010 2:50 pm
by nardi11011
This is probably what you need, but I'm not sure what exactly you're trying to do here. You might be approaching the problem the wrong way, but if you really want to use a function as an argument to another function take a look at this: http://www.learncpp.com/cpp-tutorial/78 ... -pointers/

Re: Question about functions

Posted: Tue Apr 13, 2010 9:17 pm
by xiphirx
You are right on! Function pointers. Thanks!