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)?
That gets you to the point where you have
Derived1::IsEqual(const Base& base)
Called. From here you have some options
If the number of derived is small and finite, you can implement
virtual bool Base::IsEqualToDerived(const Derived1& d) {return false};
virtual bool Base::IsEqualToDerived(const Derived2& d) {return false};
as virtual methods. In Derived1, you override and compare for real.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With