blob: 70c354410a15467591cfe50fcaae0f8625ae0899 [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.
Zesstra7ea4a032019-11-26 20:11:40 +01009
MG Mud User88f12472016-06-24 23:31:02 +020010 Usually the overloading is wanted and intended by the inheriting
11 object to change the behaviour of the function it overloads.
12 To call the overloaded functions from the overloading object the
13 ::-operator is used.
Zesstra7ea4a032019-11-26 20:11:40 +010014
MG Mud User88f12472016-06-24 23:31:02 +020015 From outside the object only one of the functions can be called
16 via call_other() or the like; this will be the topmost of all
17 overloaded functions.
18
19 Normally an overloading function is declared the same way as the
20 overloaded function, this means it has the same number and types
21 of arguments. If an object wants to change the behaviour of the
22 function in a way that it can get more arguments than the original
23 function, it has to use the modifier 'varargs' or a compiler error
24 will be raised.
25
26EXAMPLE
27 File /players/alfe/a.c:
28
29 foo() { write("A"); }
30
31 File /players/alfe/b.c:
32
33 foo() { write("B"); }
34
35 File /players/alfe/c.c:
36
37 inherit "players/alfe/a";
38 inherit "players/alfe/b";
39
40 foo() {
41 a::foo();
Zesstra7ea4a032019-11-26 20:11:40 +010042 b::foo();
43 write("C");
44 }
MG Mud User88f12472016-06-24 23:31:02 +020045
Zesstra7ea4a032019-11-26 20:11:40 +010046 To call "players/alfe/c"->foo() will now result in the output of
47 ABC.
MG Mud User88f12472016-06-24 23:31:02 +020048
49SEE ALSO
50 modifiers(LPC), inheritance(C), functions(LPC)