Default implementations in inherited interfaces

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 21 05:42:14 PDT 2016


On Thursday, 21 July 2016 at 09:41:27 UTC, Saurabh Das wrote:
> I have an interface A which declares a certain function. A 
> second interface B inherits from A and wishes to provide a 
> default implementation for that function.

You can't, interfaces cannot have implementations of virtual 
functions. Your code is trying to define two separate functions 
with the same name (the compiler should probably prohibit that, 
since it doesn't do want you want it to do).

Your best bet is to make B an abstract class instead of an 
interface. Then it can override interface functions. Of course, 
it will also tie you down as you can only inherit from one class, 
but it will actually work.



More information about the Digitalmars-d-learn mailing list