C++ Double Dispatch for Equals()

When you create methods like this: virtual bool is_equal(Shape& circle) { return false; }; And in the subclass, virtual bool is_equal(Circle& circle) { return true; }; These are not the same method. You have two separate virtual methods, neither of which is overridden (they are overloaded not even overloaded, as Ben Voigt pointed out). When … Read more

Understanding double dispatch C++

Well, obviously, you really don’t have fightwho declared in your Creature class, so you need to declare it there, and declare it as virtual. Double dispatch works in a way that for call (this assumes Warrior& w = …, not Warrior w): w.fight(m); First the virtual mechanism will chose Warrior::fight instead of Monster::fight and then … Read more