[help]operator overloading with opEquals in a class

Steven Schveighoffer schveiguy at yahoo.com
Wed Nov 3 11:23:15 PDT 2010


On Wed, 03 Nov 2010 13:57:09 -0400, Benjamin Thaut  
<code at benjamin-thaut.de> wrote:

> Am 03.11.2010 13:07, schrieb zhang:
>> 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.
[snip]
>
> I'm not shure if it is a bug or not, but to fix it you could add "alias  
> object.opEquals opEquals;" before your first opEquals. Had that already  
> many times, it also happens a lot with opCmp.

First, it's not a bug, you should only ever override with bool  
opEquals(Object).  Second, using the alias trick does not work for  
opEquals.  x == y *specifically* calls  
(cast(Object)x).opEquals(cast(Object)y).  So if you did that, your  
override would never be called.

-Steve


More information about the Digitalmars-d mailing list