-
Notifications
You must be signed in to change notification settings - Fork 0
/
CallingParentFunctions.sol
65 lines (54 loc) · 1.1 KB
/
CallingParentFunctions.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
/*
calling parent functions
- direct
- super
E
/ \
F G
\ /
H
*/
contract E {
event Log(string message);
function foo() public virtual {
emit Log("E.foo");
}
function bar() public virtual {
emit Log("E.bar");
}
}
contract F is E {
function foo() public virtual override {
emit Log("F.foo");
// direct method
E.foo();
}
function bar() public virtual override {
emit Log("F.bar");
// using keyword "super"
super.bar();
}
}
contract G is E {
function foo() public virtual override {
emit Log("G.foo");
// direct method
E.foo();
}
function bar() public virtual override {
emit Log("G.bar");
// using keyword "super"
super.bar();
}
}
contract H is F, G {
function foo() public override(F, G) {
F.foo();
}
function bar() public override(F, G) {
// "super" calls the function "bar()" in all the parents of the Contract H
super.bar();
}
}