January 2019
Intermediate to advanced
512 pages
14h 5m
English
What would be the equivalent of the pure virtual function in this scenario? A pure virtual function must be implemented in all derived classes; a class that declares a pure virtual function, or inherits one and does not override it, is an abstract class; it can be further derived from, but it cannot be instantiated.
When we contemplate the equivalent of a pure virtual function for static polymorphism, we realize that our CRTP implementation suffers from a major vulnerability. What happens if we forget to override the compile-time virtual function, f(), in one of the derived classes?
template <typename D> class B { public: ... void f(int i) { static_cast<D*>(this)->f(i); }};class D : public B<D> { // ...