issues with global structs

Since I graduated from college, the definition of struct has changed, particularly in C++.

I am trying to define a global array of structs, outside of main, and provide access to them from a header file.

globals.hpp file
extern struct a_struct glob[100];

globals.cpp file

struct a_struct glob[100] = {
{ glob1 },
{ glob2 },
...
{ glob100 }
}

But the gcc C+98 compiler will NOT initialize this array of global structs.

Right now I am using a hugemongous switch statement to return just one glob, when you send in an index, such as

a_struct get_glob(int i) { return globi; }

but this is a lot of work to maintain. I would like an initializer, just like an Excel csv spreadsheet file layout, since I have hundreds of objects to handle, like a big spreadsheet.

Any ideas? I did use constructors with 0 or n-parameters inside the struct statement (since struct in C++ is similar to a class) but the compiler still won't initialize, even with the -std - c++0x compiler flag.

I have no problem initializing inside of a function or main, that is moot.



Topic archived. No new replies allowed.