CRTP (Static Polymorphism)
Explore how to convert dynamic polymorphism into static polymorphism using the Curiously Recurring Template Pattern (CRTP) in C++. Understand the template-based approach to efficient compile-time method resolution and how it improves runtime efficiency by eliminating virtual tables.
We'll cover the following...
We'll cover the following...
Dynamic polymorphism code
Let’s look at the same code that we used in the dynamic polymorphism section.
In the code above, we have the base class Person inherited by the derived class Student. We can see that the type print() function is called depending on the object type. This call to the print() function will be resolved at the runtime (dynamic polymorphism). Our job is to change ...