Consider the following code snippet:
bool SomeObject::equal(const SomeObject& rhs) const
{
if (this == &rhs)
{
return true;
}
// check the state
}
The problem with this code is that SomeObject might override operator& (or someone might add it in the future), which in turn may break this implementation.
Is it possible to test whether rhs and *this are the same object without being at the mercy of operator& implementation?
If you want to get the actual address of the object and ignore overloaded
&operators then usestd::addressofReference: http://en.cppreference.com/w/cpp/memory/addressof