#include <iostream>
template<typename Impl>
struct renderer{
void get(){
static_cast<Impl*>(this)->get();
}
};
struct open_gl : public renderer<open_gl>{
void get(){
std::cout << "OpenGL" << std::endl;
}
};
struct direct_draw : public renderer<direct_draw>{
void get(){
std::cout << "DX" << std::endl;
}
};
template<typename T>
void print_renderer(renderer<T> r){
r.get();
}
int main() {
auto gl = open_gl();
auto dx = direct_draw();
print_renderer(gl);
print_renderer(dx);
}
Why can't I change the parameter of print_renderer to
void print_renderer(const renderer<T> &r)
?cannot convert 'this' pointer from 'const renderer<open_gl>' to 'renderer<open_gl> &'
`Why do I get a runtime error when I rename the method
get
in open_gl from get to get1? Shouldn't this trigger a compiler error?Error = Stack overflow
**Note I am using the latest MSVC