Implement Interface Using Super

bauss jj_1337 at live.dk
Sun Jan 27 09:33:05 UTC 2019


On Sunday, 27 January 2019 at 09:31:46 UTC, bauss wrote:
> On Sunday, 27 January 2019 at 05:37:57 UTC, Jonathan Levi wrote:
>> This works in LDC but not DMD?
>>
>> ```
>> class A : B, I {
>>     alias i = typeof(super).i;
>> }
>> class B {
>>     void i() {
>>         writeln("i");
>>     }
>> }
>> interface I {
>>     void i();
>> }
>> ```
>>
>> Is this a bug in DMD or in LDC?  How can I get this effect 
>> correctly?
>
> There is no bug here.
>
> A does not implement i as a function which it should.
>
> What you want to do is to override i within A and then call 
> super.i() in the function.
>
> An alias does not substitute an implementation and I think 
> that's good because it could really cause some nasty hijacking 
> bugs.
Should probably have posted solution:

```
class A : B, I {
     override void i() {
         super.i();
     }
}
class B {
     void i() {
         writeln("i");
     }
}
interface I {
     void i();
}
```



More information about the Digitalmars-d-learn mailing list