[help]operator overloading with opEquals in a class

Tomek Sowiński just at ask.me
Wed Nov 3 13:27:16 PDT 2010


Dnia 03-11-2010 o 13:07:25 zhang <bitworld at qq.com> napisał(a):

> // It works
> //    bool opEquals(Object a)
> //    {
> //        writefln("running here.");
> //        return data == (cast(AClass)a).data;
> //    }

It should be:

override equals_t opEquals(Object o)
{
     writefln("running here.");
     if (auto a = cast(AClass) o)
         return data == a.data;
     else
         return false;
}

I'm surprised it even compiled without 'override'.

BTW, anybody knows what the equals_t bool alias is for?

-- 
Tomek


More information about the Digitalmars-d mailing list