Spec reads: 3. It is illegal to refer to this implicitly or explicitly prior to making a constructor call. Although it's allowed.
---
class A
{
int a;
this(){ M(); this(1); }
this(int b){ a=b; }
void M(){ writeln("A.M"); }
}
class B:A
{
int b;
this(){ M(); super(); b=5; }
override void M(){ writeln("B.M ",b); }
}
int main()
{
auto b=new B();
b.M();
return 0;
}
---
output is
---
B.M 0
B.M 0
B.M 5
---
We see how virtual method is called prior to constructor calls and overridden method from derived class is called from the constructor of the base class (called on not yet constructed object).
Comment #1 by nfxjfg — 2010-10-16T12:44:26Z
Same problem with D1.
Also see bug 5056.
Comment #2 by bugzilla — 2012-01-23T01:31:18Z
Compiler bug, not a spec issue.
Comment #3 by robert.schadek — 2024-12-13T17:50:46Z