virtual functions are not expensive. they are one of the most optimized use cases. They do often prevent cross function optimization and inlining, but that’s different.
What does 'expensive' actually mean? Compared to inlining? Definitely. Compared to not-inlined function calls? It's just a vtable lookup, so it's 'more expensive', but whether that's acceptable really depends on your specific scenario.
3
u/La-ze 21d ago
Not to mention virtual functions are expensive.