I would like to create a global object (for an OLED display), which can have one of two possible display classes assigned to it at run-time, such that the attached display type can be selected (one time only) with an external pin value (HIGH/LOW).
In pseudo-code:
<sometype>* oled;
if (digitalRead(PIN_SELECT))
oled = new Adafruit_SSD1306();
else
oled = new Adafruit_SH1106G();
oled->begin();
oled->print("123");
can be the base class Adafruit_GFX, but this will not of course give me access to the member functions of the selected Adafruit_XXX library. I've done some reading about dynamic casting, but it is beyond my current understanding as to whether that is the right approach to follow.
Is what I'm trying to achieve achievable? Any help much appreciated.