Object oriented programming and interfaces
Craig Dillabaugh
craig.dillabaugh at gmail.com
Mon Dec 4 21:02:59 UTC 2017
On Monday, 4 December 2017 at 20:43:27 UTC, Dirk wrote:
> Hi!
>
> I defined an interface:
>
> interface Medoid {
> float distance( Medoid other );
> uint id() const @property;
> }
>
> and a class implementing that interface:
>
> class Item : Medoid {
> float distance( Item i ) {...}
> uint id() const @property {...}
> }
>
> The compiler says:
> Error: class Item interface function 'float distance(Medoid
> other)' is not implemented
>
> Is there a way to implement the Item.distance() member function
> taking any object whose class is Item?
Interfaces are expected to implement static or final functions.
See #6 at:
https://dlang.org/spec/interface.html
interface Medoid {
static float distance( Medoid other );
uint id() const @property;
}
class Item : Medoid {
static float distance( Item i ) { return 0.0f; }
uint id() const @property { return 1; }
}
More information about the Digitalmars-d-learn
mailing list