How to initialize a struct/class that has huge array members?

253 views Asked by At

Is there a way to initialize a C++ struct/class with very large array members? I would like to initialize them by filling them with any kind of data besides an empty array. The following code is defined in a dependency of mine:

#define WORSE_DATA_LENGTH 8000

struct LibraryStruct {
    int lots;
    int of;
    int fields;
    int huge_array[2000]; // how to initialize this?
    char even_worse[WORSE_DATA_LENGTH]; // how to initialize this?
};

Note that there are not any defined constructors. It should be assumed that I cannot edit this struct.

Here's the code I've tried to make use of LibraryStruct with:

int main() {
    // I can do this, but can I fill these arrays with data?
    // Say, for example:
    //  - fill huge_array with 2000 random ints 
    //  - fill even_worse with the current day of the week in 20 different languages
    const auto my_struct = LibraryStruct{5, 8, 900, {}, {}};
    return 0;
}

I've looked around and all of the examples with initializer lists with arrays that I've found have arrays with a small number of elements, and I think this example demonstrates a need for another way to initialize arrays.

0

There are 0 answers