How should one implement
operator==(const Base& base)
to compare subclasses s.t. the calls would be properly dispatched when called as
Base* base1 = new Derived1();
Base* base2 = new Derived2();
base1->operator==(*base2)?
How should one implement
operator==(const Base& base)
to compare subclasses s.t. the calls would be properly dispatched when called as
Base* base1 = new Derived1();
Base* base2 = new Derived2();
base1->operator==(*base2)?
This seems like a generic C++ question on classes and type rather than a specific question on the operator== . Up to my knowledge, in the particular example you are giving there is no other way but to use dynamic_cast
That gets you to the point where you have
Called. From here you have some options
If the number of derived is small and finite, you can implement
as virtual methods. In Derived1, you override and compare for real.