Class Cat defines a virtual function named speak, so its subclasses may provide an appropriate implementation ( e . g . either meow or roar ).
22.
The override special identifier means that the compiler will check the base class ( es ) to see if there is a virtual function with this exact signature.
23.
In this example, the virtual void f ( ) final; statement declares a new virtual function, but it also prevents derived classes from overriding it.
24.
In particular, through the Curiously Recurring Template Pattern, it's possible to implement a form of static polymorphism that closely mimics the syntax for overriding virtual functions.
25.
Polymorphism can be distinguished by when the implementation is selected : statically ( at compile time ) or dynamically ( at run time, typically via a virtual function ).
26.
Method overloading should not be confused with forms of polymorphism where the correct method is chosen at runtime, e . g . through virtual functions, instead of statically.
27.
In object-oriented languages such as C + +, this can easily be achieved by virtual functions, where each represents an operation that can be performed on a node.
28.
SystemVerilog's polymorphism features are similar to those of C + + : the programmer may specifically write a virtual function to have a derived class gain control of the function.
29.
On the other hand, AOT usually cannot perform some optimizations possible in JIT, like runtime profile-guided optimizations, pseudo-constant propagation or indirect / virtual function inlining.
30.
In such a case, a common solution is to create a clone ( ) ( or similar ) virtual function that creates and returns a copy of the derived class when called.