Overriden method not detected ?

chmike via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 3 05:03:29 PDT 2016


When trying to compile the following code I get a compilation 
error

----
import std.stdio;

class Info
{
     final string name() { return nameImpl(); }
     protected abstract string nameImpl();
}

final class MyInfo : Info
{
     this() { assert(__ctfe); }
     private __gshared info_ = new MyInfo; // Line 12

     static string name() { return "MyInfo"; }
     protected override string nameImpl() { return name(); }
}

void main()
{
     writeln("Hello world!");
}
----
source/app.d(12,31): Error: cannot create instance of abstract 
class MyInfo
source/app.d(12,31):        function 'string nameImpl()' is not 
implemented

If I move the info_ static variable declaration after the 
nameImpl method declaration, there is no error anymore.

Is this normal ? What rule is in play here ? Or is this a 
compiler bug ?



More information about the Digitalmars-d-learn mailing list