grr...seriously, it feels like I am going in circles :(
I just don't see the point of polymorphism...i mean I see the the point point, but not how it is implemented.
Why we need it to be pointers, and then the use of virtuals..
When a child class inherits from a base class, assuming they had the same function print() for example - print() is not virtual. the print() for the derived class(assuming an implementation was made for it) would execute, otherwise the base class's execute..
If it is able to do that already, why do we need to use virtual keyword(apart from making a class abstract) at all?
if there is no use of virtuals, then no need for vtables..
as for vtables, the compiler makes a table of virtual (non pure) functions in the order of which they're declared i assume, the functions belong to their respective class(how they're implemented differently)
which in turn points to a function itself..at least what the book said...again I don't see the point of vtables..
if i was to
ptr->print()...it is going to know anyway which print() function to execute, automatically overriding a the base class's if a body is provided for the child class..if it can do that anyway, why have a vtable vector in memory????!
While I see why the concept of polymorphism is useful, I just don't get how it works "under the hood"..can someone please enlighten me.