Let's say that Beta is a subclass of Alpha, and it can either create a new method scope () or add a virtual one.
It makes no difference if you are talking with a beta pointer. But if you are talking to Alpha *, which points to a Beta object, you will get the Alpha method. If you do not declare the function virtual.
There is a function dispatch table in the Beta subclass, which is a copy of the Alpha table, but with additional beta methods at the end. If Beta simply overrides the method, it will go into the Beta section of the distribution table, so links to Alpha * will not see the new method. But, if the new method is virtual, it will go into the Alpha section of the Beta class table.
Suppose you have a subclass of Circle from Shape. And let it be said that you have a pointer to a Shape object, x, which happens to be an instance of Circle. x-> area () will see only the part of the function table related to Shape. If Circle serves as a virtual area, it appears in the "Form" section of the table. If Circle simply redefines the region, then the region method will be placed in the circular part of the table, and Shape * x will not see the new function.
In C ++, there is only one function table for each class. This is a bit confusing for people who are used to writing in a scripting language, where each object has its own distribution table. Thus, scripting languages are extremely inefficient. Imagine that all the space is occupied for each object.
Vagrant
source share