Why do we need virtual functions in C++?
@lebyy▲ 0 net votes
Problem: From what I've read, virtual functions are functions in the base class that you can override in its derived classes. But earlier, when learning about basic inheritance , I was able to override base functions in derived classes without using virtual . What am… Fix (from the top answer): Here is how I understood not just what virtual functions are, but why they're required: Let's say you have these two classes: class Animal { public: void eat() { std::cout << "I'm eating generic food."; } }; class Cat : public Animal { publ In your main function: Animal *animal = new Animal; Cat *cat = new Cat;…