Early binding and Late binding in C++ Last Updated : 05 Feb, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. Early Binding (compile-time time polymorphism) As the name indicates, compiler (or linker) directly associate an address to the function call. It replaces the call with a machine language instruction that tells the mainframe to leap to the address of the function. By default early binding happens in C++. Late binding (discussed below) is achieved with the help of virtual keyword) CPP // CPP Program to illustrate early binding. // Any normal function call (without virtual) // is binded early. Here we have taken base // and derived class example so that readers // can easily compare and see difference in // outputs. #include<iostream> using namespace std; class Base { public: void show() { cout<<" In Base \n"; } }; class Derived: public Base { public: void show() { cout<<"In Derived \n"; } }; int main(void) { Base *bp = new Derived; // The function call decided at // compile time (compiler sees type // of pointer and calls base class // function. bp->show(); return 0; } Output: In Base Late Binding : (Run time polymorphism) In this, the compiler adds code that identifies the kind of object at runtime then matches the call with the right function definition (Refer this for details). This can be achieved by declaring a virtual function. CPP // CPP Program to illustrate late binding #include<iostream> using namespace std; class Base { public: virtual void show() { cout<<" In Base \n"; } }; class Derived: public Base { public: void show() { cout<<"In Derived \n"; } }; int main(void) { Base *bp = new Derived; bp->show(); // RUN-TIME POLYMORPHISM return 0; } Output: In Derived Comment More infoAdvertise with us Next Article Structured binding in C++ H Himanshi_Singh Follow Improve Article Tags : Misc C++ cpp-virtual cpp-inheritance Practice Tags : CPPMisc Similar Reads How to Use Binder and Bind2nd Functors in C++ STL? Functors in C++ (also known as function objects) are objects that can be treated as if they are functions. They can be called a function, but they can also have an internal state and can be passed around like any other object. This can be useful when you want to pass a function as an argument to ano 4 min read map::begin() and end() in C++ STL The std::map::begin() and std::map::end() are built-in functions used to retrieve iterators to the beginning and the end of a std::map container. Both functions are member functions of the std::map class defined inside the <map> header file.Example:C++// C++ Program to illustrate the use of // 4 min read Bind Function and Placeholders in C++ Sometimes we need to manipulate the operation of a function according to the need, i.e changing some arguments to default, etc. Predefining a function to have default arguments restricts the versatility of a function and forces us to use the default arguments and that too with similar values each ti 4 min read Working and Examples of bind () in C++ STL In C++, the std::bind function is a part of the Standard Template Library (STL) and it is used to bind a function or a member function to a specific object or value. It creates a new function object by "binding" a function or member function to a specific object or value, allowing it to be called wi 5 min read Structured binding in C++ Prerequisite : Tuples in C++ Structured binding is one of the newest features of C++17 that binds the specified names to subobjects or elements of initializer. In simple words, Structured Bindings give us the ability to declare multiple variables initialized from a tuple or struct. The main purpose 5 min read Dynamic Binding in C++ Dynamic binding in C++ is a practice of connecting the function calls with the function definitions by avoiding the issues with static binding, which occurred at build time. Because dynamic binding is flexible, it avoids the drawbacks of static binding, which connected the function call and definiti 3 min read Like