[help]operator overloading with opEquals in a class
zhang
bitworld at qq.com
Wed Nov 3 05:07:25 PDT 2010
This code belown can be compiled with DMD 2.050. However, it throws an error message:
core.exception.HiddenFuncError: Hidden method called for main.AClass
I'm not sure about whether it is a bug. Thanks for any help.
import std.stdio;
class AClass
{
int data;
// It's wrong
bool opEquals(AClass a)
{
writefln("running here.");
return data == a.data;
}
// It works
// bool opEquals(Object a)
// {
// writefln("running here.");
// return data == (cast(AClass)a).data;
// }
}
int main(string[] args)
{
AClass class1 = new AClass();
AClass class2 = new AClass();
if(class1 == class2)
writefln("==");
else
writefln("!=");
return 0;
}
----------
Zhang <bitworld at qq.com>
s
More information about the Digitalmars-d
mailing list