Note that there are some explanatory texts on larger screens.

plurals
  1. PO"Method '%s' hides virtual method of base type '%s'". What's really being hidden?
    primarykey
    data
    text
    <p>After having read <a href="https://stackoverflow.com/users/12597">Ian Boyd</a>'s constructor series questions (<a href="https://stackoverflow.com/questions/3874330/delphi-how-to-hide-ancestor-constructors">1</a>, <a href="https://stackoverflow.com/questions/3876040/delphi-understanding-constructors">2</a>, <a href="https://stackoverflow.com/questions/3876484/delphi-how-to-add-a-different-constructor-to-a-descendant">3</a>, <a href="https://stackoverflow.com/questions/3877063/delphi-when-does-reintroduce-hide-ancestors-and-when-does-it-show-them">4</a>), I realize I don't quite grasp the literal meaning on what's being hidden.</p> <p>I know (correct me if I'm wrong) <code>override</code>'s sole purpose is to be able to have polymorphic behavior, so that run-time can resolve a method depending on the actual type of an instance - as opposed to the declared type. Consider the following code:</p> <pre><code>type TBase = class procedure Proc1; virtual; procedure Proc2; virtual; end; TChild = class(TBase) procedure Proc1; override; procedure Proc2; // &lt;- [DCC Warning] end; procedure TBase.Proc1; begin Writeln('Base.Proc1'); end; procedure TBase.Proc2; begin Writeln('Base.Proc2'); end; procedure TChild.Proc1; begin inherited Proc1; Writeln('Child.Proc1'); end; procedure TChild.Proc2; begin inherited Proc2; Writeln('Child.Proc2'); end; var Base: TBase; begin Base := TChild.Create; Base.Proc1; Writeln; Base.Proc2; Base.Free; Readln; end. </code></pre> <p>Which outputs:</p> <blockquote> <p>Base.Proc1<br />Child.Proc1<br /><br />Base.Proc2</p> </blockquote> <p>The warning on <code>TChild.Proc2</code> <a href="http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/cm_hidden_virtual_xml.html" rel="nofollow noreferrer">states that</a> this method "<em>will hide access to the base's method of the same name</em>". What I see is, if I don't override <code>Proc2</code> I loose the ability of the method's resolving to its actual type, not of its base type. How's that hiding access to base's method?</p> <p>Further, down the documentation on the warning as a solution to the warning, it is stated that:</p> <blockquote> <p>First, you could specify override to make the derived class' procedure also virtual, and thus allowing inherited calls to still reference the original procedure.</p> </blockquote> <p>Now, if I create a 'TChild' instance from a 'TChild' (no polymorphism), the inherited call in the non-overridden method clearly refers to the original procedure. If I create the 'Child' instance from a 'TBase', the call does not even resolve to a 'TChild' method, how could I call 'Inherited' that would refer to anything at all?</p> <p>What am I misunderstanding? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload