[SOLVED] Question about functions

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
xiphirx
Chaos Rift Junior
Chaos Rift Junior
Posts: 324
Joined: Mon Mar 22, 2010 3:15 pm
Current Project: ******** (Unkown for the time being)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Contact:

[SOLVED] Question about functions

Post 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:
Last edited by xiphirx on Wed Apr 14, 2010 2:57 pm, edited 1 time in total.
StarCraft II Zerg Strategy, open to all levels of players!

Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of :)
User avatar
hurstshifter
ES Beta Backer
ES Beta Backer
Posts: 713
Joined: Mon Jun 08, 2009 8:33 pm
Favorite Gaming Platforms: SNES
Programming Language of Choice: C/++
Location: Boston, MA
Contact:

Re: Question about functions

Post 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.
"Time is an illusion. Lunchtime, doubly so."
http://www.thenerdnight.com
nardi11011
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 9
Joined: Thu Jan 28, 2010 3:24 pm

Re: Question about functions

Post 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/
User avatar
xiphirx
Chaos Rift Junior
Chaos Rift Junior
Posts: 324
Joined: Mon Mar 22, 2010 3:15 pm
Current Project: ******** (Unkown for the time being)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Contact:

Re: Question about functions

Post by xiphirx »

You are right on! Function pointers. Thanks!
StarCraft II Zerg Strategy, open to all levels of players!

Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of :)
Post Reply