You can't have templates in interfaces unless they are final, otherwise it won't work right.

The way I'd do it is is make the op template final, and have it forward to another normal virtual function:

interface Addable {
   final Addable opBinary(string op : "+")(Addable rhs) {
        return this.opAdd(rhs);
   }

   /* virtual */ Addable opAdd(Addable rhs);
}

class Test : Addable {
    override Addable opAdd(Addable rhs) {
            return new Test();
    }
}

void main() {
   auto test = new Test();
   auto test2 = new Test();

   auto sum = test + test2;
}

Reply via email to