Geas MUD, enter the Aventure!
Geas Home | Play the Game

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1.1 The basics of the function type

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:

my_func(string str, int value)
    write("The string is '" + str + "' and the value is " + value + ".\n");

The function is then called, as demonstrated earlier, by giving the function name followed by a list of the arguments within brackets:

    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:

    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.

This document was generated by Ronny Wikh on July, 8 2003 using texi2html