I need to initialize a static array. Not all of the values are sequential.
Something like this works fine for a sequential array:
class Foo {
public:
static const char * name[];
}
const char * Foo::name[] = { "Sun", "Moon" };
How can I assign values at arbitrary positions in the array? I need to do something like this (pseudocode):
const char * Foo::name[] = { 67: "Sun", 68: "Moon" };
The array will never be bigger than 255; the indices come from byte values.
I found part of a thread where someone gives an example of something similar to what I want, but I couldn't get anything like this to work.
type array[SIZE] = {[SIZE-4]=1, 2, 3, 4};
[SIZE-4]=1are called designated intializers and are only available in C and illegal in C++ (however, in gcc they offer it as an extension). However, non-trivial (i.e. your example) are not supported.