[help]operator overloading with opEquals in a class
bearophile
bearophileHUGS at lycos.com
Wed Nov 3 14:15:31 PDT 2010
Andrei:
> That hidden functions are signaled during run time and not compile time
> is a misunderstanding between design and implementation. There should
> not be a HiddenFunc exception and the compiler should just refuse to
> compile the program.
If you compile this program, derived from the OP one:
import std.c.stdio: puts;
class Foo {
int x;
bool opEquals(Foo other) { // wrong
puts("running here.");
return this.x == other.x;
}
}
void main() {
auto f1 = new Foo();
auto f2 = new Foo();
puts((f1 == f2) ? "==" : "!=");
}
With -w, it doesn't compile and gives the error:
test.d(3): Error: class test.Foo object.Object.opEquals(Object o) is hidden by Foo
That warning just needs to become an error message as soon as possible. See:
http://d.puremagic.com/issues/show_bug.cgi?id=4216
It's in my list of about 20 very small changes that I'd like to see ASAP in D2.
Bye,
bearophile
More information about the Digitalmars-d
mailing list