You can test for object identity by comparing the addresses held by two pointers. You mention Java; this is similar to testing that two references are equal.
MyCloth* pcloth1 = ...
MyCloth* pcloth2 = ...
if ( pcloth1 == pcloth2 ) {
// Then both point at the same object.
}
You can test for object equality by comparing the contents of two objects. In C++, this is usually done by defining operator==
.
class MyCloth {
friend bool operator== (MyCloth & lhs, MyCloth & rhs );
...
};
bool operator== ( MyCloth & lhs, MyCloth & rhs )
{
return ...
}
With operator== defined, you can compare equality:
MyCloth cloth1 = ...
MyCloth cloth2 = ...
if ( cloth1 == cloth2 ) {
// Then the two objects are considered to have equal values.
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…