| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Functions are accessed through function pointers. As has been demonstrated implicitly earlier, every function call basically is nothing but a dereferenced function pointer along with a list of arguments. Take this simple example:
void
my_func(string str, int value)
{
write("The string is '" + str + "' and the value is " + value + ".\n");
return;
}
|
The function is then called, as demonstrated earlier, by giving the function name followed by a list of the arguments within brackets:
e.g.
my_func("smurf", 1000);
|
Now we add the idea of the function type where the address of the function can be taken and assigned to another variable:
e.g.
function new_func;
new_func = my_func; // or equivalent
new_func = &my_func();
my_func("smurf", 1000); // or equivalent
new_func("smurf", 1000);
|
Beware that before the variable new_func has been set to a proper
value, it doesn't refer to any function at all. Using it will cause a
run-time error.