I am trying to a initialise an array of structs in a std::array
. I know that the following is a way of initialising an std::array
with integers.
std::array<int, 5> arr { {1, 2, 3, 4, 5} };
Scenario:
But, say I have an array of structs like this
struct MyStruct {
const char *char_val_1;
const char *char_val_2;
int int_val_1;
double d_val_1;
} my_struct_obj[] = {
{ "a1b1" , "a2b1" , 1 , 1.1 },
{ "a1b2" , "a3b1" , 2 , 1.2 },
{ "a1b3" , "a4b1" , 3 , 1.3 },
{ "a1b4" , "a5b1" , 4 , 1.4 },
{ "a1b5" , "a6b1" , 5 , 1.5 },
{ "a1b6" , "a7b1" , 6 , 1.6 },
{ "a1b7" , "a8b1" , 7 , 1.7 },
{ "a1b8" , "a9b1" , 8 , 1.8 },
{ "a1b9" , "a10b1" , 9 , 1.9 },
};
Question:
How can I create an std::array
of MyStruct
s each initialised with different set of values?
Aucun commentaire:
Enregistrer un commentaire