opEquals does not work?

Namespace rswhite4 at googlemail.com
Fri Jun 7 14:02:13 PDT 2013


On Friday, 7 June 2013 at 20:58:40 UTC, w0rp wrote:
> On Friday, 7 June 2013 at 20:51:13 UTC, Namespace wrote:
>> I got it. I must use Object instead of A... How ridiculous. I 
>> thought this was already fixed...
>
> The class opEquals is quite like .equals in Java. You need to 
> match the signature of Object, which is implicitly the base 
> class of all classes. I think I recommend something like this.
>
> override bool opEquals(Object o) const {
>     auto other = cast(A) o;
>
>     // It's probably easy to miss out !is null here, which 
> matters.
>     return other !is null && this.id == other.id;
> }

Yes, I remember. As I heard it the first time I thought it's 
because of the limited compiler and that it will fixed some day.


More information about the Digitalmars-d-learn mailing list