#include <cstdlib>
#include <iostream>
//////////////////////////////////////////////////////////////////////////////////
struct Base1
{
Base1( unsigned& val ) : m_val( val ){}
bool operator==( const Base1& rhs )const { return m_val == rhs.m_val; }
unsigned& m_val;
};
//////////////////////////////////////////////////////////////////////////////////
struct Base2
{
Base2( unsigned& val ) : m_val( val ){}
bool operator==( const Base2& rhs ) const { return m_val == rhs.m_val; }
unsigned& m_val;
};
//////////////////////////////////////////////////////////////////////////////////
class Derived : public Base1 , public Base2 // Real problem has many more more Base classes
{
public:
Derived( unsigned& val1 , unsigned& val2 ) : Base1( val1 ) , Base2( val2 )
{
}
bool operator==( const Derived& rhs ) const // How to generalize this
{
const Base1& rhsBase1 = rhs;
const Base2& rhsBase2 = rhs;
const Base1& thisBase1 = *this;
const Base2& thisBase2 = *this;
return ( thisBase1 == rhsBase1 ) && ( thisBase2 == rhsBase2 );
}
};
//////////////////////////////////////////////////////////////////////////////////
int main()
{
unsigned val1 = 42 , val2 = 24 , val3 = 0;
Derived d1( val1 , val2 );
Derived d2( val1 , val3 );
std::cout << ( d1 == d2 ) << std::endl;
return EXIT_SUCCESS;
}
//////////////////////////////////////////////////////////////////////////////////
I2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCi8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8KCnN0cnVjdCBCYXNlMQp7CglCYXNlMSggdW5zaWduZWQmIHZhbCApIDogbV92YWwoIHZhbCApe30KCWJvb2wgb3BlcmF0b3I9PSggY29uc3QgQmFzZTEmIHJocyApY29uc3QgeyByZXR1cm4gbV92YWwgPT0gcmhzLm1fdmFsOyB9Cgl1bnNpZ25lZCYgbV92YWw7Cn07CgovLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vL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