Passing a type as paramter to super

Ali Çehreli acehreli at yahoo.com
Thu Jan 4 20:41:48 UTC 2018


On 01/04/2018 11:16 AM, Marc wrote:
> For code generation purposes, I'd like to pass a type name to base 
> class. I'm not sure if it's supported, I didn't find anything at 
> documentation for class constructor but it does compile:
> 
>> class A {
>>     static {
>>         int a, b;
>>     }
>>
>>     this(T)() {
>>
>>     }
>> }
> 
> then do something like this:
> 
>> class B {
>>  this() {
>>    super!B;
>>  }
>> }
> 
> but I got the error:
> 
>> found ! when expecting ; following statement

Checkout the "this template parameter":

class A {
     static {
         int a, b;
     }

     this(this T)() {
         import std.stdio;
         writeln(T.stringof);
     }
}

class B : A {
     this() {
         super();
     }
}

void main() {
     auto b = new B();
}

Ali


More information about the Digitalmars-d-learn mailing list