operator overloading and templates
jimmy
zsu0915 at yahoo.com.tw
Tue Oct 4 09:24:52 PDT 2011
Hi,
I have the following code.
struct Foo(int DIM) {
Foo!(DIM) opBinary(string op) (Foo!(DIM) rhs)
if (op == "+" || op == "-")
{
return Foo!(DIM)();
}
}
unittest {
auto u = Foo!(2)();
auto v = Foo!(2)();
assert(u + v == u);
}
I got the following during my test.
Z:\proj\D\gas>rdmd --main -unittest a.d
rdmd --main -unittest a.d
a.d(12): Error: incompatible types for ((u) + (v)): 'Foo!(2)' and
'Foo!(2)'
Failed: dmd -unittest -v -o- "a.d" -I"." >a.d.deps
I have no idea why the incompatible types error occurred.
More information about the Digitalmars-d-learn
mailing list