I was following this tutorial, trying to understand virtual table
and the whole process behind pointer
and virtual functions in C++
.
Not sure, when I have code like this:
D1 d1;
Base *dPtr = &d1;
dPtr->function1();
Why do I need all of this virtual table
management? Why compiler simply don't assign the memory address of d1
(or base, if there aren't any) overridden virtual function
?
I mean: it could elaborate there at compile time if it needs the D1 functon1()
address or Base functon1()
address. It know at that time. Why lose time and resources later at runtime looking on virtual tables
?
I miss this point. Fancy example?