Operator overloading giving encrypted error messages.

bearophile bearophileHUGS at lycos.com
Tue Feb 8 15:49:55 PST 2011


Charles McAnany:

> My issue here is that I have already used the exact same syntax in the first
> unit test as my code for the ++ overload has, but here it fails me. (Plus, why
> is line 166 having trouble with opBinary? ++ is unary, no?
> Any ideas?

In similar situations I suggest you to keep reducing your code until you have a minimal test case. Your code reduced:

struct Foo {
    Foo opUnary(string op:"++")() {
        return this;
    }
    Foo opBinary(string op)(int y) {
        return this;
    }
}
void main() {
    auto f = Foo();
    f++;
}

It sees the post-increment fires the opBinary template too. I think this is a front-end bug, for Bugzilla if confirmed and not already present.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list