Unlike many modern languages with quite flexible object models, C++ implements one vtable per class. The vtables contents are fixed up by the time the program starts running.
So in your example, there are two vtables, one for Base, one for Der. Both vtables have one entry.
The vtable of Base has the address of Base::get.
The vtable of Der has the address of Der::get.
You create an instance of Der and place it in b.
When you call b->get(), the indirection causes the actual function address to be looked in the vtable of Der, whcih gives you Der::get. So Der::get() is called.
I'm not sure what all that vptr(1000) -----> vTable(2000)-> get() stuff is about.
but how the pointer is getting changed |
Nothing is getting changed, it's just looking up a table that's been previously prepared.