How can a base class call a method in a derived class?
Within a class, calls like: $.method() are resolved at parse time; so it's not possible to use this syntax to call derived class methods unless the method also defined in the base class with a compatible signature (Qore 0.8.0+ supports parameter type definitions and method overloading). In Qore 0.8.1+, $.method() calls will be resolved at runtime if the runtime class of the object is different from the class where the method is defined.
To call a derived class method from a base class, use $self.method() instead. By using $self, you ensure that the call is resolved at run-time, so if the object belongs to a derived class and the method exists in the derived class, the derived class method will be called instead of the base class method (if any base class method with this name exists).
With Qore 0.8.0+, $object.method() calls are resolved at parse time as well, if type information is available for the object; if the runtime object class differs, then a runtime lookup of the method is used using the runtime class information. This is done for performance reasons, and is a good reason to declare type information for lvalues when the lvalues hold classes and execute methods on them.
| Next > |
|---|





