Hi there!
Is it possible to override a generic array that is declared in a parent class and call a method on the child (which is declared in a generic manner in the parent) which actually uses the array from the child itself? I know that in C++ I should allways use predefined array sizes and buffers in code. So actually the size is predefined but in a child class. Hope I explained it well enough.
Parent .h:
class SCTFTScreen
{
public:
Adafruit_ILI9341 & tft;
SCTFTScreen(Adafruit_ILI9341 & tftInstance, int index);
int numSubviews = 0;
SCTFTView * subviews[];
void printNames();
};
Parent .cpp:
void SCTFTScreen::printNames()
{
for(int i=0;i<numSubviews;i++)
{
SCTFTView * v = subviews[i];
v->printName();
}
}
Child .h:
class I2CScreenScan : public SCTFTScreen
{
public:
I2CScreenScan(Adafruit_ILI9341 & tftInstance, int index);
SCTFTView * subviews[2];
}
Child .cpp:
I2CScreenScan::I2CScreenScan(Adafruit_ILI9341 & tftInstance, int index) : SCTFTScreen(tftInstance, index)
{
index = index;
btnScan = new SCTFTTouchButton("SCAN",tftInstance,0,290,60,30);
btnSettings = new SCTFTTouchButton("CONSOLE",tftInstance,180,290,60,30);
numSubviews = 2;
subviews[0] = (SCTFTView*) btnScan;
subviews[1] = (SCTFTView*) btnSettings;
}
Somewhere else in code:
I2CScreenScan * screen(tft,0);
screen->printNames();
Should result in:
SCAN
CONSOLES
I tried to do that and the compiler didnt complain. It runs the code for i=0 fine. Any higher numbers crashes the ESP. So I suspect this is a memory address problem?!
Thank you very much!