B
Brian Tyler
I have got into the following habit for overloading the == operator:
class A {
const bool operator==( const A& rhs ) {
return bool( this == &rhs ? true : /* some condition */ );
}
};
I.e. first I check if the variables are actually the same variable, if
not I implement some logic to test for equality of the underlying data
members.
Is this first test a total waste of time (since the number of times I
actually check a variable against itself is probably zero)... hmm, that
pretty much answers my own question, but your opinions would be
appreciated.
Thanks,
Brian.
class A {
const bool operator==( const A& rhs ) {
return bool( this == &rhs ? true : /* some condition */ );
}
};
I.e. first I check if the variables are actually the same variable, if
not I implement some logic to test for equality of the underlying data
members.
Is this first test a total waste of time (since the number of times I
actually check a variable against itself is probably zero)... hmm, that
pretty much answers my own question, but your opinions would be
appreciated.
Thanks,
Brian.