The C ++ standard imposes several restrictions on the implementation of virtual functions and the call mechanism. However, since it lists a lot of things that cannot be virtual, it actually adds freedom.
From n3797 10.3 / 1:
Virtual functions support dynamic binding and object-oriented programming.
Then there are a lot of things about what constitutes overriding and final overrider .
From 5.2.2 / 1:
Otherwise [the function is virtual], its final redefinition (10.3) is called in the dynamic type of the expression of the object; such a call is called a virtual function call. [Note: the dynamic type is the type of the object referenced by the current value of the expression of the object ...]
Thus, the C ++ standard defines a limited type of dynamic dispatch, based on the dynamic type of an object, and nothing more. As long as each object carries a mechanism by which any virtual function can be called, everything else can be captured.
Yes, vtables are common, but they are not the last word. They require significant memory and speed, especially for multiple inheritance. I can easily come up with a mechanism that is not vtable, but it is just as fast and uses less object memory, but takes up more space in code or static memory. Various researchers have developed many methods, and some have even been patented. There are methods that provide better type safety, better branch prediction, or even faster searches. I donβt see much point in providing links - they are also easy to find.
But no, I am not aware of any production C ++ compilers that use any of these mechanisms. Maybe it's time to think about one thing?
source share