early binding for dummies [closed]

I have been recently looking forward to understanding vtables, early binding and late binding for methods in its OOP context.

But all explanations i’ve found, in books, videos, posts, were rather “black boxes” as if to call them. All i’ve found was the obvious code examples of the sort “Base vs Derived” and only a mention of vtable but not even a thorough explanation other than our fellow vpointer that secretly exists, Im just not finding any information on the web regarding how these protocols fit into the compile time or run time.

Is there any clear algorithm to these protocols?
Such that; when we have A* a = new B() and do a.foo(), the program checks if foo is in A’s vtable and then if it is, it calls foo from B’s vtable. But if there’s early binding we call from A….

There is no clear step by step process to how these things fit together, there’s no clear recipe to how the program behaves, we just jump from compilation to run-time just knowing everything perfectly without any clear explanation.

is it normal or am I just coming to the realization that programming is hard and nothings ever gonna be clear?

I am puzzled at how there are people here who know their stuff when there is no easy to get info in the internet.

I am eager to learn this stuff to the bone, but there’s no clear path. Does anyone have a good source to get into understanding these inner workings?

  • 1

    Some of us got our education before there was an internet. We had an old technology called “books”. 🙂 But anyway, the vtable and stuff are all implementation details – one way to implement what the standard requires. The language standard says nothing on how to do this, only about how it should work. Like “If a actually points to a derived class, call the function from the derived class”. That’s about it!

    – 

  • @BoP Could also be we were more used to how things where before C++, so we could still reason in assembly and the concept of a vtable is very easy to understand from that angle. Jump to the address of index 2 in the table… just one tiny little indirection. In a derived class make a copy of the baseclass table and modify the address at index 2 and suddenly the code jumps to a differenct function 😉

    – 

  • _”the program checks if foo is in A’s vtable…” The program never makes this check, because the compiler already knows what functions are virtual. The compiler always decides if there’s early (compile time) binding.

    – 

  • I am not oblivious to books, it’s just that I am an undergrad working on my education and the path to understanding these things is not very clear. Thanks for the feedback, I was a bit shocked to see my precious 15 pts crumble in a matter of seconds and thought i was done for. If I ever get them back ill make sure to upvote you guys. Cheers

    – 




Leave a Comment