Polymorphism (Greek for "many forms") enables a single interface to control a general class of actions. In C++, polymorphism manifests in two distinct forms: Compile-Time (Static) and Runtime (Dynamic).
| Polymorphism Type | Resolution Mechanism | Language Features | Performance |
|---|---|---|---|
| Compile-Time (Static) | Compiler resolves addresses during compilation | Function Overloading, Operator Overloading, Templates | Zero overhead (Fastest) |
| Runtime (Dynamic) | Resolved at execution time via VTable pointers | Virtual Functions, Abstract Base Classes, Method Overriding | Minor pointer indirection (~1 nanosecond) |
Boost your C++ proficiency by studying these closely connected core modules:
Under the hood dispatch mechanics.
Compile-time static polymorphism.
Generic compile-time polymorphism.