Implementing interfaces using alias this
Balagopal Komarath via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jun 14 04:34:37 PDT 2017
On Wednesday, 14 June 2017 at 09:41:49 UTC, ketmar wrote:
> Balagopal Komarath wrote:
>
>> Why doesn't this work? The Test!Duck type has a void quack()
>> method but the compiler says it is not implemented.
>
> 'cause `alias this` is *not* a tool that can be used to emulate
> inheritance. no, `quack` is NOT impemented. `alias this` won't
> automagically paste the code.
Thanks for the reply. Is there any reason for disallowing this?
AFAIK, the alias this guarantees that the interface provided by
Test!T is a superset of the interface provided by T. And, when T
= Duck, T provides everything required by IDuck. Couldn't the
compiler check while instantiating that Test!Duck provides all
methods required by IDuck?
More information about the Digitalmars-d-learn
mailing list