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:
[SOLVED] Question about functions
Moderator: Coders of Rage
- xiphirx
- 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
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
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
- hurstshifter
- 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
I'm not 100% sure about what you are looking to accomplish but for this example that you listed...
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.xiphirx wrote:drawButton(screen, image, 10, 10, events, rotateMap(90));
"Time is an illusion. Lunchtime, doubly so."
http://www.thenerdnight.com
http://www.thenerdnight.com
-
- Chaos Rift Newbie
- Posts: 9
- Joined: Thu Jan 28, 2010 3:24 pm
Re: Question about functions
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/
- xiphirx
- 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
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
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