qore
qore copied to clipboard
Overload/override interactions
Consider:
class Base {
f(int x) {
printf("int version\n");
}
f(number x) {
printf("number version\n");
}
b() {
f(1);
}
c() {
f(1.1);
}
}
class Derived inherits Base {
f(float x) {
printf("float version\n");
}
}
Derived d();
d.b();
d.c();
Output:
float version
float version
The float
version in Derived
seemingly overrides both int
and number
versions of Base
, though the `number version can still be called:
d.f(1.1n);
So it does not override them completely. This can get messy with multiple inheritance:
class B1 {
f(float x) {
printf("float version in B1\n");
}
z() {
print("z() in B1\n");
}
}
class B2 {
f(int x) {
printf("int version in B2\n");
}
x() {
f(1);
}
z() {
print("z() in B2\n");
}
}
class D inherits B1, B2 {
}
D d();
d.x();
d.z();
Output:
float version in B1
z() in B1