4 lwc implements the attribute 'final'. When a virtual function is declared
5 final it cannot be overriden in derrived objects. This can lead to certain
6 optimizations in some -rather rare- cases, where virtual calls are converted
7 to direct member calls. An example:
20 Generally, the approach with auto-functions is more powerful and can
21 optimize more cases. In the above example, foo could have been declared an
22 auto function and the f() call would also be a member call in this case.
23 'final' is helpful in such a situation:
41 Here, with 'final' the f() call is a member call and the k() call a virtual
42 call in 'foo'. final is used to optimize functions which have a pointer to
43 an object 'B' and below it -- in other words when calling virtual functions
44 with pointers to derrived objects. This is rather rare in OOP but not
47 B. Virtual inheritance
48 ~~~~~~~~~~~~~~~~~~~~~~
50 Just like a non-pure virtual function overrides a pure one, a final virtual
51 function overrides a non-final one. For example:
72 d.f (); // calls C.f() !
75 If both C.f and B.f are final, it is an error.
78 Finally, final-functions and auto-functions do not stack up.
79 We could interpret final as a directive to stop automatically
80 redefining the function, but at the moment 'auto' ignores
81 'final' and this leads to a reasonable error. Send proposals