I'm fairly new to c++, and am trying to create a const pointer array to hold shortcuts to a few structures.
The issue I'm having is that C++03 (or the compiler I'm using - gcc 4.4.7) apparently doesn't support constant pointer arrays? Or at least you can't create them for existing objects?
To clarify, the pointers themselves are to be constant, but the objects they point to are variable. And the array structure is crucial because it greatly simplifies my code if I can access these objects by index later on.
This is for work with spacecraft hardware that has flight heritage or something, so it's not feasible to use a newer compiler :/
struct Type1 {
unsigned short thing1;
};
struct Type2 {
Type1 thing2;
};
struct Type3 {
Type2 thing3;
};
class A {
Type3 Array[4];
Type1 *const pArray[4] = {
&Array[0].thing3.thing2,
&Array[1].thing3.thing2,
&Array[2].thing3.thing2,
&Array[3].thing3.thing2
};
};
error: a brace-enclosed initializer is not allowed here before ‘{’ token
error: ISO C++ forbids initialization of member ‘pArray’
error: making ‘pArray’ static
error: invalid in-class initialization of static data member of non-integral type ‘MyType* const [4]’
So is it even possible to do what I'm trying to do given the compiler I'm using?