Concept:
Early binding refers to binding in the compile phase
Late binding refers to run phase binding
Example:
Class Base
{
void Fun () {}
}
Class Bind:class Base
{
Void fun () {}
}
Main ()
{
Base base;
Base->fun ();
Bind *tmp;
TMP = &base;
Tmp->fun ();
}
The above example shows you whether there is a grammatical problem, in fact, I deliberately, the fun function is covered
First, say Base->fun (); it's a process.
A base object was created when the program was run, Base->fun (); What is it?
If you understand the object to call the function in the object, then it becomes the runtime to find the function, that good early binding it?
C + + compile, base->fun () is actually equivalent to fun (base), so a look is not the function address! is indeed a function address,
This also indirectly indicates that the member function in C + + is a unique global address, and the object is a hidden argument.
Early binding refers to the decision in the compilation phase of how to call, compiled to determine the call address, of course, determine the way to call, so that is early binding.
Why does Tmp->fun invoke Bind's fun function because C + + uniquely determines the globally unique function by the function name + variable type + number of variables.
This is why the C + + function call design is not the same as the reason for it!
In fact, when you are understanding the early binding technology, I think I can also handle late binding technology.
Late binding is used to solve polymorphic properties (polymorphic properties are not explained here)
Late binding means that even if you assign a value, you can correctly invoke the correct function.
The solution for C + + is:
When a function is called and a special tag (virtual) is checked, the address is not called directly, and a vptr is taken out of the base object.
vptr points to the virtual table so that the function can be correctly found to be called. Which is to wrap around and,
Of course, it is easy to say, it is difficult to achieve such a function.
Alternative solutions:
The virtual function is saved directly to the object, and when the special tag (vitrual) is checked, the function address is called directly.
When I think the plan is immature. Just to show that late binding is the technology we often use, and
Not mysterious, special, complex.
Popular analysis of early binding and late binding techniques