<div dir="ltr"><div><div><span style="font-family:courier new,monospace">Hi All,<br><br>I am reading this document: <a href="http://www.freepascal.org/docs-html/ref/refsu29.html">http://www.freepascal.org/docs-html/ref/refsu29.html</a> and doing an experiment with the following code:<br>
<br>program project1;<br>{$mode objfpc}{$H+}<br>type<br> TBase = class<br> constructor Create; virtual;<br> end;<br> TDerived = class(TBase)<br> constructor Create; override;<br> end;<br><br>var<br> c1, c2: TBase;<br>
c3: TDerived;<br><br>constructor TDerived.Create;<br>begin<br> WriteLn('Entering TDerived.Create');<br> inherited Create;<br> WriteLn('Leaving TDerived.Create');<br>end;<br><br>constructor TBase.Create;<br>
begin<br> WriteLn('Entering TBase.Create');<br> Writeln('Leaving TBase.Create');<br>end;<br><br>begin<br> WriteLn('Creating a TBase and assigning to TBase variable...');<br> c1 := TBase.Create;<br>
WriteLn('Creating a TDerived and assigning to TBase variable...');<br> c2 := TDerived.Create;<br> WriteLn('Creating a TDerived and assigning to TDerived variable...');<br> c3 := TDerived.Create;<br>end. <br>
<br><br></span></div><span style="font-family:courier new,monospace">The problem is, it makes NO DIFFERENCE at all in the following cases:<br><br></span></div><div><span style="font-family:courier new,monospace">CASE 1:<br>
<br></span></div><div><span style="font-family:courier new,monospace">TBase.Create;<br></span></div><div><span style="font-family:courier new,monospace">TDerived.Create;<br><br></span></div><div><span style="font-family:courier new,monospace">CASE 2:<br>
<br></span></div><div><span style="font-family:courier new,monospace">TBase.Create; virtual;<br></span></div><div><span style="font-family:courier new,monospace">TDerived.Create; virtual;<br><br></span></div><div><span style="font-family:courier new,monospace">CASE 3:<br>
<br></span></div><div><span style="font-family:courier new,monospace">TBase.Create; virtual;<br>TDerived.Create; override;<br><br></span></div><div><span style="font-family:courier new,monospace">According to the document, "inherited" cannot be used in non-virtual methods, and it is wrong to use virtual in sub-class. But my test shows the contrary. BTW, I am running Linux on 64bit platform.<br>
<br></span></div><div><span style="font-family:courier new,monospace">Regards,<br>Shannon</span><br></div><div><br><br><br></div><div><div><br></div></div></div>