opEquals
Dan
dbdavidson at yahoo.com
Wed Dec 5 11:58:22 PST 2012
On Wednesday, 5 December 2012 at 00:17:05 UTC, deed wrote:
> interface I
> {
> bool opEquals(I i);
> }
>
> class C : I
> {
> bool opEquals(I i)
> {
> return true;
> }
> }
>
> void main()
> {
> I i1 = new C;
> I i2 = new C;
> assert(i1 == i2); // Assertino failure
> assert(i1 != i2); // Passes, although it's the opposite of
> what I want..
> }
>
> What's missing?
It looks like you want the opEquals to be called and it is not.
Match the signature of it to what is in object.di. This may be
what you want.
----------------------------------
import std.stdio;
interface I
{
bool opEquals(Object i);
}
class C : I
{
override bool opEquals(Object i) const
{
writeln("Called");
return true;
}
}
void main()
{
I i1 = new C;
I i2 = new C;
writeln(i1 == i2);
writeln(i1 != i2);
}
More information about the Digitalmars-d-learn
mailing list