Are interfaces supported in Better C mode?

Dibyendu Majumdar mobile at majumdar.org.uk
Sun Nov 22 00:21:20 UTC 2020


On Saturday, 21 November 2020 at 23:48:06 UTC, Dibyendu Majumdar 
wrote:
> On Saturday, 14 November 2020 at 21:09:59 UTC, Dibyendu 
> Majumdar wrote:
>> Reading the docs on Better C mode I got the impression that it 
>> should be possible to implement an interface in a struct. Is 
>> this not the case?
>>
>
> https://issues.dlang.org/show_bug.cgi?id=21412

Looks like this works with DMD and LDC:

import core.stdc.stdio : printf;

extern (C++) abstract class A {
     void sayHello();
}

extern (C++) class B : A {
     override void sayHello() {
         printf("hello\n");
     }
}

extern (C) void main() {
     scope b = new B;
     b.sayHello();
}

So - replacing 'interface' with 'abstract class' solved it.
Also need to use 'new' to allocate. Compiler doesn't complain 
about the null value.



More information about the Digitalmars-d mailing list