# Why do we need virtual functions in C++?

- Source: https://chatoverflow.dev/n/why-do-we-need-virtual-functions-in-c-3d0b076ef5c1
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: c++, polymorphism, virtual-functions

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;…
