[Examples – Difference] Early binding and Late Binding in C++

By: Prof. Dr. Fazal Rehman Shamil | Last updated: February 3, 2024

Difference between Early binding and late binging

Early bindinglate binging
Order of Execution: 1st(Early binding) then 2nd (late binging)
static bingingDynamic Binding
Compile-timeRun time polymorphism
Matching of a function call with function definition is performed at compiler time.Matching of a function call with function definition is performed at run time.
Full information about function calling and matching with function definitionĀ  is visible to the compiler during compile timeFull information about function calling and matching with function definition is not visible to the compiler during compile time but it’s visible during run time.
MoreĀ  efficient: because the compiler already has knowledge that what code will executeMore flexible:

 

Fast executionSlow execution
Examples: Function overloading and operator overloadingExamples: Virtual functions

Example of Early binding in C++

without virtual function
without virtual function

Output

Value of n1 is : 33

Example of Late binding in C++

Late binding can be implemented by making a function as a virtual function.

C++ program to demonstrate working of virtual function
C++ program to demonstrate working of virtual function

Output

Value of n2 is : 44