answersLogoWhite

0

Late binding, or dynamic binding, occurs at runtime. Early binding, or static binding, occurs at compile time. The difference between the two is that, with early binding, the compiler knows exactly which function will be called in advance and can statically bind to that function during compilation. With late binding, the compiler does not know which function will be called in advance, it only knows the function signature. Thus the binding has to be done at runtime.

For example, if you call a virtual function of a base class, the compiler cannot determine in advance the exact type of the derivative (in some cases it may not be derived at all). All it knows is that you've called the base class method and that an override may or may not exist at runtime. Thus the exact method to be called will ultimately be determined at runtime, via the derived class' virtual table. Note that although the derived class is itself late bound (because the compiler cannot know the exact type of a derivative that may be made available in the future), only the virtual methods of the base class need to be late bound. Non-virtual methods can be statically bound, since they are never expected to be overridden.

Calling virtual methods is actually no different to using function pointers within your code (a virtual table is simply an array of function pointers, with one table per base class, and another for each of its derivatives). Again, the compiler cannot know in advance where a function pointer will actually be pointing at compile time, thus the call must be dynamically bound at runtime.

User Avatar

Wiki User

11y ago

Still curious? Ask our experts.

Chat with our AI personalities

ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
RafaRafa
There's no fun in playing it safe. Why not try something a little unhinged?
Chat with Rafa

Add your answer:

Earn +20 pts
Q: What is late bound function call in C plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering