Declaring interfaces with a constructor

David Zhang via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 13 12:31:52 PDT 2017


On Monday, 13 March 2017 at 17:52:09 UTC, XavierAP wrote:
> On Monday, 13 March 2017 at 02:15:21 UTC, David  Zhang wrote:
>> What it says on the tin. Is there a way to create interfaces 
>> with a constructor or must I use an abstract class.
>
> What do you want to do in your constructor? I can't think of 
> anything that wouldn't change some state, either of the class 
> (but interfaces aren't allowed to have fields either, precisely 
> because they may not have state), or the global state 
> (worse...). Just curious.
>
>> Additionally, is there a way to force the linker to link a 
>> function in a class without an implementation with another 
>> that does have an implementation?
>
> I'm not sure if you mean the same as generating "interface 
> files"?
> [1] https://dlang.org/dmd-windows.html#interface-files

Basically, I want to define a common interface for a group of 
platform-specific classes, except that they should ideally also 
share constructor parameters. What I want to do is then alias 
them to a common name, selecting the implementation for the 
target platform at compile time.


More information about the Digitalmars-d-learn mailing list