🎓 Unit 8: Virtual Functions and Polymorphism

A virtual function in C++ is a member function declared in a base class using the virtual keyword and intended to be redefined (overridden) in derived classes. Its primary purpose is to achieve runtime polymorphism, allowing the correct function implementation to be called based on the actual type of the object, even when accessed through a pointer or reference to the base class.


1. Early Binding vs Late Binding

Binding refers to the process of converting identifiers (such as variable and performance names) into addresses. Binding is done for each variable and functions. For functions, it means that matching the call with the right function definition by the compiler. It takes place either at compile time or at runtime.

image.png

🔹 Early Binding (Static Binding)

🔹 Late Binding (Dynamic Binding)