Multiple struct definitions

I have a class with a class.h and i have a global.h (witch hold global macros and a struct) The global.h is included both in the main.cpp and the class.cpp and this give me the error:
"struct carbon * carbs" (?carbs@@3PAUcarbon@@A) already defined in creature.obj

This is what creating all the fuzz i think:

1
2
3
4
5
6
7
8
9
10
11
12

struct carbon
{
	int holdingId;
	bool state;
	float x_pos; 
	float y_pos; 
	float z_pos;
};

carbon carbs[CARBS];


It seems like the struct should be outside of globals.h, but how can I then access it both from main.cpp and class.cpp?
One way is to add extern before the declaration in the header file, and to then create the actual variable in one of the .cpp files

http://www.learncpp.com/cpp-tutorial/42-global-variables/

Global variables are not very popular - the discussion at the bottom mentions some alternatives.
Moschops, thanks for replying. I can see from the last example in the link that global variables are so evil, they are capable of starting WW3! This is bad :-) I shal try another way of doing this.
Topic archived. No new replies allowed.