Templated Interfaces?

Benji Smith dlanguage at benjismith.net
Sun Aug 24 07:56:07 PDT 2008


I've been trying to create a templated interface, and can't figure out 
what I'm doing wrong. Here's the basic example:

interface I(T) {
   public T x();
}

class C(T) : I(T) {
   private T value;
   public this(T val) { this.value = val; }
   public T x() { return value; }
}

void main() {
   I!(char) c = new C!(char)('a');
   char value = c.x();
}

I've tried many many slight variations of this, to try to satisfy the 
compiler, but it always rejects the code, usually by saying something 
like "Interface I used as a type".

Of course! That's because interface I *is* a type.

What am I doing wrong?

--benji


More information about the Digitalmars-d-learn mailing list