[OT] Delphi class type
Bastiaan Veelo
Bastiaan at Veelo.net
Tue Apr 2 19:16:58 UTC 2019
On Tuesday, 2 April 2019 at 17:00:41 UTC, pham wrote:
[...]
> Skeleton sample in Delphi
>
> type
> A = class
> create() virtual // constructor
> writeln('A.create')
>
> B = class(A)
> create() override // constructor
> //inherited create() // call inherited constructor
> implement if needed
> writeln('B.create')
>
> ClassType = class of A; // Any class inherited from A can be
> used to set to this type
>
>
> ClassType x = A;
> var x1 = x.create() // output 'A.create'
> x = B
> x1 = x.create() // output 'B.create'
So in Delphi you can skip calling the constructor of the base
class if you omit `inherited create()`? That would be rather odd.
D does the right thing:
---
import std.stdio;
class A
{
this() { writeln(__FUNCTION__); }
}
class B : A
{
this() { writeln(__FUNCTION__); }
}
void main()
{
A a = new A; // Output A.this
a = new B; // Output A.this, B.this.
}
---
https://run.dlang.io/is/6b2T4D
Bastiaan.
More information about the Digitalmars-d
mailing list