- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Early binding and Late binding in C++
In this section we will see what is early binding and what is late binding in C++. The binding means the process of converting identifiers into addresses. For each variables and functions this binding is done. For functions it is matching the call with the right function definition by the compiler. The binding is done either at compile time or at runtime.
Early Binding
This is compile time polymorphism. Here it directly associates an address to the function call. For function overloading it is an example of early binding.
Example
#include<iostream> using namespace std; class Base { public: void display() { cout<<" In Base class" <<endl; } }; class Derived: public Base { public: void display() { cout<<"In Derived class" << endl; } }; int main(void) { Base *base_pointer = new Derived; base_pointer->display(); return 0; }
Output
In Base class
Late Binding
This is run time polymorphism. In this type of binding the compiler adds code that identifies the object type at runtime then matches the call with the right function definition. This is achieved by using virtual function.
Example
#include<iostream> using namespace std; class Base { public: virtual void display() { cout<<"In Base class" << endl; } }; class Derived: public Base { public: void display() { cout<<"In Derived class" <<endl; } }; int main() { Base *base_pointer = new Derived; base_pointer->display(); return 0; }
Output
In Derived class
- Related Articles
- What is late binding in C#?
- What is early binding in C#?
- Static binding vs Dynamic binding in C#
- Static binding and dynamic binding in Java
- Difference between Static binding and dynamic binding in Java
- What is binding and binding time in compiler design?
- Dynamic Binding in C#
- What are differences between static binding and dynamic binding in Java?
- What is dynamic binding in C#?
- What is static binding in C#?
- Why early sunrise and late sunset. Explain.
- Difference Between Static and Dynamic Binding
- What is binding in Java?
- Binding function in Python Tkinter
- What is parameter binding in C# ASP.NET WebAPI?

Advertisements