The big problem with virtual calls is it hinders inlining, but if you design your API correctly that can usually be optimised away by design (put loops inside the call, don't call inside a loop)
Putting loops inside virtual functions can't work in any cases. Like when a heterogenous collection is iterated and a virtual call is performed for each object.
In such cases I prefer using std::variant instead of inheritance, but this works only if all possible types are known ahead of time.
Yeah, no human would work like that. You wouldn't write a sentence for a letter, then go shopping for a single item, then write another sentence, go shopping again, then flush the toilet ...
In such cases I prefer using std::variant instead of inheritance, but this works only if all possible types are known ahead of time.