Why do we need virtual functions in C++?

Here is how I understood not just what virtual functions are, but why they’re required: Let’s say you have these two classes: In your main function: So far so good, right? Animals eat generic food, cats eat rats, all without virtual. Let’s change it a little now so that eat() is called via an intermediate function (a trivial function just …

Read more