Why does Object.opEquals *exist*

Hasan Aljudy hasan.aljudy at gmail.com
Wed Nov 8 20:09:55 PST 2006



Bill Baxter wrote:
> Bill Baxter wrote:
>> Object.opEquals returns int for some reason.  That means I can't do 
>> something like:
>>
>>      bool func() {
>>        ...
>>        return objA == objB;
>>      }
>>
>> (Because int can't be converted to bool automatically). Instead I have 
>> to do something like
>>
>>        return (objA == objB)!=0;
>>
>> Which is just looks silly.
>>
>> Is there any good reason for opEquals to return an int?  opCmp has to, 
>> I understand, but opEquals has no business returning int.  Is this a 
>> holdover from the days before bool?
>>
>> --bb
> 
> After seeing some crashes upon comparing with null objects, I realized 
> what I actually want is:
> 
>         return objA is objB;
> 
> So I should change my question to "Why is opEqual defined by object at 
> all??"
> 
> --bb

The "is" operator just compares for references/pointers, not object 
equality.



More information about the Digitalmars-d mailing list