Abstract classes vs interfaces, casting from void*

John Colvin john.loughran.colvin at gmail.com
Sun Aug 11 13:09:43 UTC 2019


On Saturday, 10 August 2019 at 17:28:32 UTC, Alex wrote:
>
> ´´´
> void main(){}
> interface A { void fun(); }
> abstract class B{ void fun(); }
> class C : A{ void fun(){} }
> class D : B{ /*override*/ void fun(){} }
> ´´´
>
> case 1:
> interface A and class C implementing interface A:
> You don't need to "override" anything. You are forced to 
> provide an implementation of the function inside the class.
>
> case 2:
> abstract class B and class D inheriting from it:
> You can but not have to provide an implementation of a function 
> inside the abstract class.
> If I don't and do not provide any implementation inside D I get 
> a linker error. Don't how this case behaves on your system.
> If you provide an implementation inside the abstract class, you 
> don't have to provide any in the derived one.
> In any case, if you want to provide an implementation inside 
> the derived class you have to literally "override", as in D 
> implicit overrides are not allowed.

I think there's some confusion here, because B.foo is not 
abstract. abstract on a class is not inherited by its methods. 
https://dlang.org/spec/attribute.html#abstract



More information about the Digitalmars-d-learn mailing list