I'd like to add a global..

I have a class that runs the TFT touch screen. screenObj

This works wonderful.

Now, I'd like to make a global, screen; that is an instance of this class. I can do this in my sketch, but then I need to pass it into any objects constructors that wants to access it. This works, but its not the best. And it sucks up memory.

I'd like to place this gloabl somewhere like in the screenObj.h file so its automatically available to my sketch & all the subclasses and bits I write later that want to access it.

This doesn't seem to work as I thought. If I put the global in the screenObj.h I get all sorts of errors about multiple definitions.

gauge.cpp.o:(.bss.screen+0x0): multiple definition of `screen'
drawObj.cpp.o:drawObj.cpp:35: first defined here
label.cpp.o:(.bss.screen+0x0): multiple definition of `screen'
drawObj.cpp.o:drawObj.cpp:35: first defined here
screenObj.cpp.o:(.bss.screen+0x0): multiple definition of `screen'
drawObj.cpp.o:drawObj.cpp:35: first defined here

Even though I use the

#ifndef screenObj_h
#define screenObj_h

at the top with the #endif at the bottom.

Any hints?

Thanks!!

-jim lee

put the variable in the header makred as 'extern', then initialise the object in your sketch, kind of like:

Header:

extern int a;

Sketch:

extern int a = 4;

Then the variable is available by any file that includes the header. Without extern each file that includes it, gets its own copy of the data.

AH!! Thanks! I knew there was something I was forgetting.

Thanks!

-jim lee

extern int a = 4;

You don't need the "extern" there. All (global) variables are exported unless you put "static" in front of them.