August 07, 2004 Bug in operator overloading! | ||||
|---|---|---|---|---|
| ||||
class A{}
void main ()
{
A a,b;
a=new A;
b=new A;
writefln(a==b);
writefln(a<b);
writefln(a+b);
writefln(a-b);
writefln(a*b); //'a' is not an arithmetic type
}
WHY? Why don't the first four writefln's couse error messages from compiler!
I see it as a huge problem for generic programming!
For example: this template will work for the above A class
an any other class you write, even if you don't provide an opAdd
operator!
template func(Type)
{
Type func(Type a, Type b)
{
return a+b;
}
}
| ||||
August 07, 2004 Re: Bug in operator overloading! | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Ivan Senji |
> writefln(a+b);
> writefln(a-b);
These two should error but do pointer arithmetic instead. That seems like a bug.
The a==b and a<b are working as designed but by your post on the main newsgroup I think you'd like to see the design changed - which is different than the a+b and a-b examples.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply