Suppose there are two objects of different classes, and they are being compared with each other. Both classes overload the operator==() function, but in different ways. What will the result of the comparison be?
class A
{
bool operator==( const A &lhs, const B &rhs ){ return true; };
bool operator==( const B &lhs, const A &rhs ){ return true; };
};
class B
{
bool operator==( const A &lhs, const B &rhs ){ return false; };
bool operator==( const B &lhs, const A &rhs ){ return false; };
};
int main( int argc, char **argv )
{
A a();
B b();
assert( a == b ); //What's the result?
};
Aucun commentaire:
Enregistrer un commentaire