Re: compare two structs via ==
"Peter Duniho" <NpOeStPeAdM@nn owslpianmk.comw rote in message
news:op.ttgwxqm 58jd0ej@petes-computer.local. ..
On Tue, 05 Jun 2007 13:43:09 -0700, Mark Wilden <mwilden@commun itymtm.com>
wrote:
>>
>Usually, but not always.
>
No - always. That was the definition of equality.
As long as the == operator wasn't overloaded, you mean.
We're not talking about overloading ==, since that would imply comparing an
object to a different kind of object. We're talking about comparing an
object to an object of the same class - no overloading.
The behavior of operator== could be overridden, but that I would maintain
that that didn't change the definition of object equality. Someone could
overload == to format your hard drive, but that doesn't change C++'s
definition of equality, which is that two objects are equal iff. all their
members are equal.
But if someone's idea of equality was different from the language's, then
you're right - they could certainly use == to implement that idea. And that
was sometimes done, of course, for legitimate reasons.
It's hard for me to imagine, however, that two objects whose members were
equal to each other would not be equal... But I could be wrong.
And of course "equal" is not the same thing as "identical. "
///ark
"Peter Duniho" <NpOeStPeAdM@nn owslpianmk.comw rote in message
news:op.ttgwxqm 58jd0ej@petes-computer.local. ..
On Tue, 05 Jun 2007 13:43:09 -0700, Mark Wilden <mwilden@commun itymtm.com>
wrote:
>>Memberwise comparison worked pretty well in C++. An object is equal to
>>another object if all its members are equal to the other object's
>>members (using the same criterion for member equality).
>>another object if all its members are equal to the other object's
>>members (using the same criterion for member equality).
>Usually, but not always.
No - always. That was the definition of equality.
As long as the == operator wasn't overloaded, you mean.
object to a different kind of object. We're talking about comparing an
object to an object of the same class - no overloading.
The behavior of operator== could be overridden, but that I would maintain
that that didn't change the definition of object equality. Someone could
overload == to format your hard drive, but that doesn't change C++'s
definition of equality, which is that two objects are equal iff. all their
members are equal.
But if someone's idea of equality was different from the language's, then
you're right - they could certainly use == to implement that idea. And that
was sometimes done, of course, for legitimate reasons.
It's hard for me to imagine, however, that two objects whose members were
equal to each other would not be equal... But I could be wrong.
And of course "equal" is not the same thing as "identical. "
///ark
Comment