Weird opEquals Problem
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed Feb 22 18:06:33 PST 2012
On Wed, Feb 22, 2012 at 08:51:50PM -0500, Kevin wrote:
> I have the following code which gives the same result on ldc2 and
> dmd. If I compare two objects of different classes I always get
> false even though the comparator is called.
[...]
> The key thing to notice is that opEquals() gets called both times.
> Any ideas about what is happening?
It's because when A and B are different types, the compiler translates
A==B to:
A.opEquals(B) && B.opEquals(A)
Both parties need to agree before they are considered equal.
T
--
Shin: (n.) A device for finding furniture in the dark.
More information about the Digitalmars-d-learn
mailing list