Setting a function to a variable?

I need to set a function to a variable of some kind. Then later in the program it needs to run the function that is set to the variable. The variable doesn't need to change after it is set to a function, it just needs to be able to be set to a function. So maybe I don't need a variable? What do I do? :3 Is this even possible? :o

Example:
if (PosRampYes == 0)
{
SomeVariableOrSomething = FirstFunction();
}
else
{
SomeVariableOrSomething = SecondFunction();
}

//later:

SomeVariableOrSomething; //so if PosRampYes is set to 0 then this line would run FirstFunction()

Help would be greatly appreciated! :D
Last edited on
Hi
I'm no expert at these things but what comes to mind is 'Function Pointers'.
It seems to be what you are looking for.

A good explanation is under 'Function Pointer Syntax' on this link.

http://www.cprogramming.com/tutorial/function-pointers.html

Last edited on
I need to set a function to a variable of some kind.

then
So maybe I don't need a variable?

I think you answered your own question.

Example:
if (PosRampYes == 0)
{
SomeVariableOrSomething = FirstFunction();
}
else
{
SomeVariableOrSomething = SecondFunction();
}

//later:

SomeVariableOrSomething; //so if PosRampYes is set to 0 then this line would run FirstFunction()

then
Is this even possible?

Again answered your own question...
Topic archived. No new replies allowed.