This is not a direct answer to your example, but the address of your comment, which shows the wrong perspective IMHO
I just wondered about this particular problem, mostly interested if there is a more efficient way to avoid the overhead of virtual method performance
There is something to understand. Everyone has a compromise. Design models and OO have all the known advantages that we love, but they also have disadvantages, for example, too many classes, memory overhead, performance overhead due to many method calls, etc.
On the other hand, the old “procedural” method had some advantages and was objective; it was “easy” for the code (there is no need to think about how to create a system, just put everything in the main one) and have less overhead in many aspects (less memory overhead, since less classes and more compact objects are required - no need in virtual tables, etc., and fewer method calls, therefore, possibly higher performance, without the overhead of performance for dynamic binding - no matter what the costs are currently anyway ...-).
But this is not that the trade-offs of a particular instance of the problem, it is what experience has shown, which is the right way to create software. Reusing code is modular and helps in separate testing ( quality ), readable , supported , flexible for expansion - these are well-understood attributes that should be the main driver of software development.
Thus, there are some cases where a really good C / C ++ programmer could have done the “old way”, as you say, but this performance advantage that it bears for this particular program is worth the fact that no one able to support or support it afterwards?
To give another similar example: can you ask in the same way?
Why are layered architectures in web development? Just put everything in one server and it will be LOT FASTER, since there will be no latency when requesting the internal and all layers of the user interface data or network delay to request a remote database, etc.
Of course you have a point. But then ask yourself, can this scale increase the load? The answer is no. Is scalability important to you, or do you want to keep the idea of "put everything on one server"? If your income comes from electronic sites, the fact that you cannot serve more customers will not make your customer happy just because you submitted the first 100 really fast ... Anyway, this is my opinion.