blob: 06209e98bf62a624962fc64d78a84a626e45be49 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001CONCEPT
2 overloading
3
4DESCRIPTION
5 This concept is strongly connected with the concept of inheritance.
6 A function is called 'overloaded' if it is defined more than once
7 in an object. This can happen if the object inherits other objects
8 which have defined a function with the same name.
9 Usually the overloading is wanted and intended by the inheriting
10 object to change the behaviour of the function it overloads.
11 To call the overloaded functions from the overloading object the
12 ::-operator is used.
13 From outside the object only one of the functions can be called
14 via call_other() or the like; this will be the topmost of all
15 overloaded functions.
16
17 Normally an overloading function is declared the same way as the
18 overloaded function, this means it has the same number and types
19 of arguments. If an object wants to change the behaviour of the
20 function in a way that it can get more arguments than the original
21 function, it has to use the modifier 'varargs' or a compiler error
22 will be raised.
23
24EXAMPLE
25 File /players/alfe/a.c:
26
27 foo() { write("A"); }
28
29 File /players/alfe/b.c:
30
31 foo() { write("B"); }
32
33 File /players/alfe/c.c:
34
35 inherit "players/alfe/a";
36 inherit "players/alfe/b";
37
38 foo() {
39 a::foo();
40 b::foo();
41 write("C");
42 }
43
44 To call "players/alfe/c"->foo() will now result in the output of
45 ABC.
46
47SEE ALSO
48 modifiers(LPC), inheritance(C), functions(LPC)