Virtual Function mechanism in c++
Inside an ordinary member function you can imagine what will happen if you call a virtual function the virtual call is resolved at runtime because the object cannot know whether it belongs to the class the member function is in, or some class derived from it.
also..
Once the VPTR is initialized to the proper VTABLE, the object in effect "knows" what type it is.
also..
When a constructor is called, one of the first things it does is initialize its VPTR. However, it can only know that it is of the current type the type the constructor was written for. The constructor code is completely ignorant of whether or not the object is in the base of another class.
in all these texts, i dnt understand what the author means by "the object knows"??, what and how it can know? what does the word knows refer to?
also, so is it true that when we make an object and then the constructors are called from most base to current class in inheritance chain, then vptr also gets initialized in each constructor to vtable corresponding to that class in the inheritance chain till constructor of the current class is called finally in the constructor calls chain and it initializes the final state of vptr to vtable of the current class?? :confused:

