thanks!<br><br><div class="gmail_quote">On Tue, Jul 26, 2011 at 9:12 AM, bearophile <span dir="ltr"><<a href="mailto:bearophileHUGS@lycos.com">bearophileHUGS@lycos.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Diego Canuhé:<br>
<div class="im"><br>
> I'm trying to overload the "+" and "-" operators for a struct but I get<br>
> this error<br>
><br>
> test.d(47): Error: incompatible types for ((v1) - (v2)): 'Vecf!(1u)' and<br>
> 'Vecf!(1u)'<br>
> (the line corresponds to the last assert)<br>
<br>
</div>It's a dmd bug, and I think it's already in Bugzilla. This is workaround code:<br>
<br>
<br>
struct Vecf(uint n) {<br>
float x;<br>
Vecf opBinary(string op)(Vecf other) if (op == "+" || op == "-") {<br>
mixin("return Vecf(this.x " ~ op ~ " other.x);");<br>
}<br>
}<br>
<br>
void main() {<br>
alias Vecf!1 V;<br>
auto v1 = V(3f);<br>
auto v2 = V(5f);<br>
auto r = V(-2f);<br>
assert ((v1.opBinary!"-"(v2)) == r); // better to use an approximate ==<br>
assert ((v1 - v2) == r); // better to use an approximate ==<br>
}<br>
<br>
Bye,<br>
<font color="#888888">bearophile<br>
</font></blockquote></div><br>