0

This should print "GLES2", but it doesn't. Is there a way to fix that?

#include <iostream>
#include <string>

using namespace std;

class Rasterizer {
protected:
        virtual string get_driver_name() const { return "???"; }
        Rasterizer();
};

class RasterizerGLES2 : public Rasterizer {
        virtual string get_driver_name() const { return "GLES2"; }
};

Rasterizer::Rasterizer() {
        cout << get_driver_name();
}

int main() {
        RasterizerGLES2();
}

http://codepad.org/dHZYtOeB

anatoly techtonik
  • 19,847
  • 9
  • 124
  • 140
  • _"Is there a way to fix that?"_ Well you can, using a template. For this direction lookup for _Static Polymorphism_ and the [_CRTP_](https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern). – πάντα ῥεῖ Apr 23 '16 at 07:12
  • I would like to avoid this getting more complicated. The only solution I see now is explicit call to some parent `init()` function with this functionality. – anatoly techtonik Apr 25 '16 at 08:03

0 Answers0