Global Struct

This is where I can't keep things straight...

I have file that is called "global.cpp" and another which is called "global.h"

I use these two files to manage a few global variables. For example, I do this in the CPP file --

char szBuffer[MAX_PATH];

and then in the header file I do this --

extern char szBuffer[MAX_PATH];

All works fine, of course.

But I can't work out how to do a struct doing the same thing. I want a simple global struct, but there are MANY .cpp and .h files, so I have to do it in a global namespace so that all of these files have access to it, but so as the linker won't get upset with it. So what I am trying to do is what I did in the above with the char szBuffer[MAX_PATH], i.e...

1
2
3
4
5
6
7
8
9
10
11
struct BOSSTABOPEN {
int iTAB;
char* lpTab;
};

BOSSTABOPEN bto[] = {
0, "tab1",
1, "tab2",
2, "tab3",
3, "tab4"
};


No matter which combinations I've used in the .cpp file and the .h file, it won't compile or it won't work. When I have got it to compile, it isn't recognized in my other files.

So how can I declare and use this simple struct in a global namespace?
Last edited on
Lines 1 to 4 in global.h and lines 6 to 11 in global.cpp. Furthermore, add extern struct BOSSTABOPEN bto[]; to global.h.
Last edited on
Perfect! Thanks very much.
Topic archived. No new replies allowed.