10-19-2011 6:14 AM
Out of curiosity I am asking this.
In Alternative 2 its mentioned that
Alternative 2
... cref->(meth_name) ... .
Effect
This form is possible for all visible methods of objects. cref can be any class reference variable that points to an object that contains the method specified in meth_name. This method is searched for first in the static type, then in the dynamic type of cref
So, If a object OBJ_C1 of type ref to Superclass C1 calls a method say M1 which is redifined in child class C2.
then if OBJ_C1 is pointing to instance of C2, and we use OBJ_C1->('M1'), As per Alternative 2, First the search for M1 is made in the static type of Object OBJ_C1 which is M1 of class C1 and then in the subclass C2. so why then Dynamic call
OBJ_C1->('M1') triggers the redifined method as if we have called it like OBJ_C1->M1 (not Dynamically)
Note: OBJ_C1->M1 does not trigger dynamic search as its a static call.
Whereas OBJ_C2->('M1') triggers SEARCH for M1 in static type and then in dynamic type if not found in static Type
10-19-2011 6:45 AM
Hello,
I guess you're confused between DEFINITION & IMPLEMENTATION
You should understand that the existence(or DEFINITION) of the method meth_name is searched for in the static type of cref, but as per the rules (of method re-definition) the IMPLEMENTATION is triggered based on the instance being referred to by cref.
Hope i'm clear.
BR,
Suhas
10-19-2011 6:45 AM
Hello,
I guess you're confused between DEFINITION & IMPLEMENTATION
You should understand that the existence(or DEFINITION) of the method meth_name is searched for in the static type of cref, but as per the rules (of method re-definition) the IMPLEMENTATION is triggered based on the instance being referred to by cref.
Hope i'm clear.
BR,
Suhas
10-19-2011 7:01 AM
Thanks Suhas, I agree with you. I am aware of the difference between Defn and Implmn ... but didnt apply that here ..
Thanks once again