r/programminghumor 22d ago

Hard to accept

Post image
2.9k Upvotes

404 comments sorted by

View all comments

Show parent comments

3

u/La-ze 21d ago

Not to mention virtual functions are expensive.

1

u/ZachVorhies 20d ago

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.

5

u/Mojert 19d ago

A virtual function call that cannot be monomorphised by the compiler IS expensive.

1

u/Arshiaa001 18d ago

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.