ref + operator overloading question

Aleksey matklad at mail.ru
Mon Sep 16 13:43:00 PDT 2013


I get strange type errors in the following code, and I don't
understand why =( Could anybody help?

struct I {
       int i;
       I opBinary(string op)(ref I that)
       if (op == "+") {
           return I(i + that.i);
       }
}

void main() {
       auto a = I(1);
       auto d = a + (a + a);
}

Error: incompatible types for ((a) + (a.opBinary(a))): 'I' and 'I'

If I remove ref or parens around (a+a) the code compiles just
fine.


More information about the Digitalmars-d-learn mailing list