Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As far as I know, there are two separate issues here:</p> <h3>Making sure the child class' constructor calls the base class' constructor</h3> <p>You'll have to <em>explicitly</em> call the base class' constructor:</p> <pre><code>constructor TMinMatrix.Create(Rows, Cols: Byte); begin inherited; //... end; </code></pre> <h3>Making sure the child class' constructor overrides the base class' constructor</h3> <p>You'll <em>also</em> have to make the child class' constructor <code>override</code>, and the base class' constructor <code>virtual</code>, to make sure the compiler sees the relation between the two. If you don't do that, the compiler will probably warn you that TMinMatrix's constructor is "hiding" TMatrix's constructor. So, the correct code would be:</p> <pre><code>type TMatrix = class protected //... public constructor Create(Rows, Cols: Byte); virtual; // &lt;-- Added "virtual" here //... type TMinMatrix = class(TMatrix) private //... public constructor Create(Rows, Cols: Byte); override; // &lt;-- Added "override" here constructor CreateCopy(var that: TMinMatrix); destructor Destroy; override; // &lt;-- Also make the destructor "override"! end; </code></pre> <p>Note that you should also make your destructor <code>override</code>.</p> <h3>Introducing a constructor with different parameters</h3> <p>Note that you can only override a constructor with the same parameter list. If a child class needs a constructor with different parameters, and you want to prevent the base class' constructors from being called directly, you should write:</p> <pre><code>type TMyMatrix = class(TMatrix) //... public constructor Create(Rows, Cols, InitialValue: Byte); reintroduce; virtual; //... end implementation constructor TMyMatrix.Create(Rows, Cols, InitialValue: Byte); begin inherited Create(Rows, Cols); // &lt;-- Explicitly give parameters here //... end; </code></pre> <p>I hope this makes things more clear... Good luck!</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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