Hard
CRTP base downcasting to the derived type
Does this program compile, and if so what does it print?
main.cpp
template <typename Derived>
struct Base {
void run() {
static_cast<Derived*>(this)->step();
}
// no fallback step() defined in Base
};
struct Concrete : Base<Concrete> {
void step() { std::cout << "Concrete::step\n"; }
};
int main() {
Concrete c;
c.run();
}7 of 44 in Design Patterns