DIP 1004 Preliminary Review Round 1

Daniel N via Digitalmars-d digitalmars-d at puremagic.com
Wed May 3 05:58:17 PDT 2017


On Wednesday, 3 May 2017 at 12:46:19 UTC, Andrej Mitrovic wrote:
> On Wednesday, 3 May 2017 at 09:13:54 UTC, Daniel N wrote:
>> However I oppose the other part of the DIP since it's already 
>> possible today.
>>
>> class FileException : Exception
>> {
>>     this(ErrorCode error_code, string file = __FILE__, uint 
>> line = __LINE__ )
>>     {
>>         super("FileNotFound", file, line);
>>     }
>>
>>     alias __ctor = super.__ctor;
>> }
>
> I was excited for a second, but that doesn't actually compile.
>
> Error: alias test.FileException.__ctor is not a constructor; 
> identifiers starting with __ are reserved for the implementation

I used this technique many times with many different compiler 
versions...

The trick is that your child class need to have defined at least 
1 constructor before the alias.

This should work:
this() {}
alias __ctor = super.__ctor;

This will give the error message you saw:
alias __ctor = super.__ctor;
this() {}



More information about the Digitalmars-d mailing list