J
Jarek Blakarz
Hi
I understand what is CRTP. What I don't understand is why CRTP is called a
static polymorphism or rather polymorphism in particular.
I think that it is "static" since the function call is resolved at compile
time, right ?
Assuming that I'm right about "static", plese explain me based on the following
example why it is "polymorphic".
thanks for clarification.
template <class Derived> struct Base {
void interface() { static_cast<Derived*>(this)->implementation(); }
};
struct Derived1 : Base<Derived1> {
void implementation() { }
};
struct Derived2 : Base<Derived2> {
void implementation() { }
};
Derived1 *d1 = new Derived1;
Derived2 *d2 = new Derived2;
d1->interface();
d2->interface();
I understand what is CRTP. What I don't understand is why CRTP is called a
static polymorphism or rather polymorphism in particular.
I think that it is "static" since the function call is resolved at compile
time, right ?
Assuming that I'm right about "static", plese explain me based on the following
example why it is "polymorphic".
thanks for clarification.
template <class Derived> struct Base {
void interface() { static_cast<Derived*>(this)->implementation(); }
};
struct Derived1 : Base<Derived1> {
void implementation() { }
};
struct Derived2 : Base<Derived2> {
void implementation() { }
};
Derived1 *d1 = new Derived1;
Derived2 *d2 = new Derived2;
d1->interface();
d2->interface();