All the materials give somewhat similar anwer to this question. "First the VPTR Pointer is initialised to it's proper VTABLE by the contructor which is automatically done by the compiler ,,,," or "You don’t ever want to be able to make a call to a virtual function before the VPTR is properly initialized. Of course, the place where initialization can be
guaranteed is in the constructor, ....." or something similar to this.
My doubt is whether the constructor in question base class constructor???
Making constructors virtual doesn't make sense.
In inheritance hierarchy objects are constructed from the base down to the lowest derived class. Making constructor virtual means that you would be using a derived class constructor before a base was even created.
What's the purpose of using a derived class if the base hasn't been created yet?
You can get the effect of Virtual Constructor by using Factory design pattern...... which doesn't violates the objected oriented rules specifically inheritance structure........ but its helpful. and some times needed....
The vptr not necessarily initialized by the compiler in the constructor it might be initialized during the construction... its totally the implementation dependent thing... i.e. to preserve the polymorphic behavior. Some compiler might not use Vptr and vTable to hold the virtual functions entries..... they might use some other structure to behave polymorphically.......
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.