Loading classes conditionally

hello, im trying to break my head to put this working...

My main goal is that i have 2 classes (1 for each screen) and i want to load only one on main.ino depending on config.

tried this aproach, but dont think is right

#ifdef xSCREEN_3.2
Screen3_2 myScreen;
#elseif xSCREEN_5_0
Screen5_0 myScreen;
#endif

both classes have same Merthods, and i want to call some methods like...
myScreen.UpdateScreen();

is this the best aproach?

Thanks a lot,

Not really sure, but maybe this?

#ifdef xSCREEN_3.2
    Screen3_2 myScreen;
#elseif defined(xSCREEN_5_0)
    Screen5_0 myScreen;
#endif

problem solved!!!

#ifdef xSCREEN_3.2
#include "screen3_2.h"
Screen3_2 myScreen;
#elseif defined(xSCREEN_5_0)
#include "screen5_0.h"
Screen5_0 myScreen;
#else
#include "screen3_2.h"
Screen3_2 myScreen;
#endif

it works as expected!! :slight_smile:

small question, this compiles both classes or only one?

thank you so much for your answers, really apreaciate :slight_smile:

x4code:
small question, this compiles both classes or only one?

thank you so much for your answers, really apreaciate :slight_smile:

Let me add to what Delta_G said....

ANY code that isn't used is not compiled in. For example, you could have a sketch with dozens of functions, but if all you do is [b]Serial.print ("Hello");[/b] the compiler will see that all the other code isn't being used and won't compile any of it.

You can try it... make a small sketch that does 2 different things, then at first only do one thing and leave the other function unused, then build it and see what size it is. Then, use the second function and watch the program get larger.

x4code:
small question, this compiles both classes or only one?

AFAIK: everything in your project directory gets complied, but only things that are referenced from your setup() and loop() get linked into the resulting binary file. So, the answer to the question that you actually wanted to ask is "only one will wind up taking up space on your arduino".