I've read the similar questions, but does anyone know why if I have a struct
struct ArabicRoman {
char roman;
int arabic;
};
I can initialise a C++ std::array
in the following way:
ArabicRoman M({'M', 1000});
ArabicRoman D({'D', 500});
array<ArabicRoman, 2> const SYMBOLS({ M, D });
I can initialise a C-style array in the following way:
ArabicRoman const SYMBOLS[]({ {'M', 1000}, {'D', 500} });
However, the following is not compiling:
array<ArabicRoman, 2> const SYMBOLS({ {'M', 1000}, {'D', 500} });
any workaround to initialise C++ style arrays of structs?
You need to replaces parentheses with braces:
std::array<ArabicRoman, 2> const SYMBOLS {{ {'M', 1000}, {'D', 500} }};
^ ^
LIVE DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With