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; }
}

Reply via email to