I am reading an example about polymorphism, which looks like below, where show () is a virtual function:
int main() { Derived dv1; Derived dv2; Base* ptr; ptr = &dv1; ptr->show(); ptr = &dv2; ptr->show(); }
The books say that in this case, the compiler will use the late binding technique. I understand the difference between late binding and early binding. However, in this example, we (and possibly the compiler) can see which function should be called, because there are no changes to the objects pointed to by ptr . So, why not early binding in this case, because later binding will cause some overhead?
c ++ late-binding
Rickie
source share