What is the difference between compile-time and runtime polymorphism?
Last updated
Compile-time (static) polymorphism resolves calls during compilation via overloading and templates. It has no runtime overhead and can be inlined.
Runtime (dynamic) polymorphism uses
virtualfunctions through base pointers/references, dispatching via a vtable based on the actual object type.Trade-off: static is faster, dynamic is more flexible and used when behavior depends on the runtime type.