What Is Binding in C++? Static (Early) and Dynamic (Late) Binding

Binding in C++ is the step that connects a function call to the actual function body that will run. It happens at compile time by default. It happens at run time only when the function is virtual and you call it through a pointer or a reference.

The two kinds have two names each.

  • Static binding is also called early binding. The compiler decides.
  • Dynamic binding is also called late binding. The program decides while running.

The rule is short. Static binding uses the declared type. Dynamic binding uses the real type of the object.

Static bindingDynamic binding
Other nameEarly bindingLate binding
DecidedAt compile timeAt run time
Applies toNormal functions, overloads, non-virtual membersvirtual members
Chosen byThe declared type of the pointer or referenceThe actual type of the object
CostNoneOne pointer lookup, and no inlining
EnablesSpeedPolymorphism

One example shows both at the same time.

#include <iostream> class Base { public: virtual ~Base() = default; virtual void show() { std::cout << "Base show\n"; } void name() { std::cout << "Base name\n"; } // not virtual }; class Derived : public Base { public: void show() override { std::cout << "Derived show\n"; } void name() { std::cout << "Derived name\n"; } }; int main() { Derived d; Base* p = &d; p->show(); // "Derived show" -> dynamic binding p->name(); // "Base name" -> static binding return 0; }

Both calls go through the same pointer. Only show is virtual, so only show reaches the derived version.

How dynamic binding works

A class with at least one virtual function gets a hidden table of function pointers. It is usually called the vtable. Every object of that class stores a hidden pointer to its class table.

A virtual call reads that pointer, looks up the slot, and jumps. That is one extra indirection. It also blocks inlining, which is the real cost in tight loops.

You get dynamic binding only when all three things are true.

  1. The function is declared virtual in the base class.
  2. The derived class defines a function with the same signature.
  3. You call it through a pointer or a reference to the base class.

The mistakes that break dynamic binding

Most binding bugs come from one of these four.

  • Forgetting virtual. Without it the base version runs, whatever the object really is.
  • Object slicing. Base b = d; copies only the base part of d. A call on b then uses Base, because b is a Base.
  • Virtual calls inside a constructor or destructor. During the base constructor the object is still a Base, so the base version runs.
  • A missing virtual destructor. delete basePtr on a derived object is undefined behaviour unless the base destructor is virtual.

Write override on every derived function that is meant to replace a virtual one. If the signature does not match, the compiler reports it instead of silently creating a new function.

Binding in C, and std::bind

C has no virtual functions, so every call in C is statically bound. Late binding in C is written by hand. You put function pointers in a struct and set them at run time, which is the same idea as a vtable.

std::bind is a different topic that shares the word. It comes from <functional> and creates a callable with some arguments already fixed. Modern code usually writes a lambda instead, because a lambda is easier to read and easier to inline.

Data binding is not a C++ language feature

Some readers search for data binding. That term means keeping a value and a screen field in step. Standard C++ has no such feature.

Frameworks add it. Qt does it with signals and slots, and QML adds property bindings. In plain C++ you write the observer pattern yourself.

How to Prepare

TAGS
Coding Interview
CONTRIBUTOR
Arslan Ahmad
Arslan Ahmad
ex-FAANG engineering manager and author or Grokking series.

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Explore Answers
Which skill will be most required by 2030?
What Is Google Chrome Written In?
Chrome is written mostly in C++, with Rust allowed for new code, JavaScript and HTML for its built-in pages, and Java, Kotlin, Objective-C, and Swift for the mobile and Mac shells.
what are ServiceNow developer interview questions?
Who earns more, AI engineer or software engineer?
What's the difference between recursion, memoization & dynamic programming?
Why is Amazon the best answer?
Related Courses
New
Grokking the AI System Design Interview course cover
Grokking the AI System Design Interview
Learn to design AI systems the way interviewers expect: classic ML products, LLM and RAG architectures, and agentic systems, all through the lens of the system design interview.
4.6
(3,192 learners)
Discounted price for Your Region

$99

Grokking the Coding Interview: Patterns for Coding Questions course cover
Grokking the Coding Interview: Patterns for Coding Questions
The 24 essential patterns behind every coding interview question. Available in Java, Python, JavaScript, C++, C#, and Go. The most comprehensive coding interview course with 543 lessons. A smarter alternative to grinding LeetCode.
4.6
Discounted price for Your Region

$197

Grokking Modern AI Fundamentals course cover
Grokking Modern AI Fundamentals
Master the fundamentals of AI today to lead the tech revolution of tomorrow.
4.1
Discounted price for Your Region

$72

Design Gurus logo
One-Stop Portal For Tech Interviews.
Copyright © 2026 Design Gurus, LLC. All rights reserved.