Frank Heckenbach wrote:
Waldek Hebisch wrote:
the in the case of overriding `b.dop' prints `b.p'. but in the case of shadowing it just prints `a.p', because `b.p' beeing a new method gets a new VMT slot, but `b.dop' calls old slot (so old method).
And Delphi does the latter? (Seems a bit contrary to the purpose of being virtual IMHO.)
Yes, Delphi uses shadowing. They have a rationale: they want to sove "fragile base class problem" (when change to base class propagates to the whole inheritance hierarchy). Most of the time you do not want/need virtual methods. But to be able to override methods in base class they have to be virtual. When you add a new method to the base class it may conflict with child methods. Their selling point is that since you did not know about new base method surely you do not want to call it.
I still like more OOP way (error in such a case), but at least it is consistent with general Delphi attitude.