Setting up TFT screens in a loop

Hello,

Im have not worked with C alot before, i only have some experience in java.
Now i have bumped into something i do not understand.

While working on a project i was trying to clean my code a bit (make it a bit more modular).
The arduino im currently working on has multiple TFT screens attached to it.
I would like to start all the screens at the start of my program without having to initialize all of them seperatly. ( This makes it easier to attach more or less screens to it in the future).

The code below does not seem to work, but i dont know why.

TFT screens[3] = {screen1, screen2, screen3};
int screensSize = 3;

void setup() {

  for (int i = 0; i < screensSize - 1; i++) {
    screens[i].begin();
    screenSetup(screens[i]);
  }
}

This on the other hand does work.

TFT screens[3] = {screen1, screen2, screen3};
int screensSize = 3;

void setup() {
  screen1.begin();
  screen2.begin();
  screen3.begin();
  for (int i = 0; i < screensSize - 1; i++) {
    
    screenSetup(screens[i]);
  }
}

In the first one you are beginning and setting up only 2 of the 3 screens and the other one you began all 3 screens, but you are only setting up 2 of them.

Also the proper way to do an array of objects is like this.

TFT * screen[3]; // create object pointer

// In setup()
for(byte i = 0; i < screensSize; i++) // 0 - 2, not 0 - 1
{
  screen[ i ] = new TFT; // initialize that object
  screen[ i ] -> begin(); // the rest of the code needs to be called with "->" instead of a "."
  screenSetup(screen[ i ]); 
}