Early Binding vs Late Binding in C++: vtable and vptr Explained
Binding means deciding which function should be called for a particular function call. In C++, this decision can happen either at compile time or at run time.
When the function call is resolved at compile time, it is called Early Binding or Static Binding.
When the function call is resolved at run time based on the actual object type, it is called Late Binding or Dynamic Binding.
Let’s look into the differences first.
| Early Binding | Late Binding |
| Happens at compile time. | Happens at run time. |
| Also called Static Binding | Also called Dynamic Binding |
| Compiler has all information to invoke correct function version at compile time. | Compiler doesn’t have information to identify correct function version. |
| Normal function calls are example of Early Binding. | Virtual functions are example of Late Binding. |
| Functions invoked by object is example of early binding | Functions invoked by pointers can be example of late binding. |
| Early binding is efficient as no cost paid at run-time for function resolution. | Late Binding is slightly costly as function resolution happens at run time. |
| Early binding doesn’t provide flexibility of one method multiple interfaces. | Late Binding provide flexibility. |
| Doesn’t have any virtual table or virtual pointer. | It uses Virtual Table and Virtual Pointer. |