implimenting interface function by inheriting from other class
Alexey
invalid at email.address
Sat Aug 21 23:06:44 UTC 2021
On Saturday, 21 August 2021 at 22:56:40 UTC, Bastiaan Veelo wrote:
> On Saturday, 21 August 2021 at 20:35:43 UTC, Alexey wrote:
>> Hello
>> ```D
>> interface Int
>> {
>> void coolFunc();
>> }
>>
>> class C1
>> {
>> void coolFunc()
>> {
>> return;
>> }
>> }
>>
>> class C2 : C1, Int
>> {
>>
>> }
>>
>> void main()
>> {
>> auto c = new C2;
>> }
>> ```
>> dmd says it's not Ok:
>> t.d(14): Error: class `t.C2` interface function `void
>> coolFunc()` is not implemented
>>
>> how to make dmd happy?
>
> Not sure if this is the best way, but it does make dmd happy:
> https://run.dlang.io/is/44F3AE
>
> ```d
>
> class C2 : C1, Int
> {
> override void coolFunc()
> {
> C1.coolFunc;
> }
> }
> ```
>
> It looks lame, I admit.
>
> — Bastiaan.
I want `this` inside of C1::coolFunc to return C2 if called as
C2::coolFunc
More information about the Digitalmars-d-learn
mailing list