header files & multiple declarations

Apr 11, 2011 at 11:29pm
hi

I've already put an "#ifndef" guard in my header file yet it still tells me that my declared objects(which I need globally) "are declared already".

Do I need to stick them in a .cpp file and if so, how can I access them? Would it work if I did?
Apr 11, 2011 at 11:34pm
When I declare my objects in a .cpp file it tells me that I can't access them anywhere else. I'm really in a dilema over this. I need my objects to be global across multiple .cpp files yet I dont want the "are declared already" message.
Apr 12, 2011 at 12:06am
Declare them as extern in some header file that is included by everyone that needs them, then make them not extern in one of your .cpp files.
Apr 12, 2011 at 12:09am
what does "extern" do? Would it help me or what can instead?
Apr 12, 2011 at 12:12am
Extern basically tells the compiler "This variable exists somewhere else." It's basically the same as a function prototype, but for variable definitions.
Apr 12, 2011 at 12:19am
thanks, extern did the trick. Today is the first time I've learnt and appreciated its meaning
Topic archived. No new replies allowed.