Называй меня читом, но ...
struct Color final
{
double grey;
double rgb[3];
};
// the cheet
#define make_color( x, a, b ) Color x { a, b[0], b[1], b[2] }
int main()
{
double myRGB[3]{ 2, 6, 9 };
make_color( c, 10, myRGB ) ; // single line construction
printf("\nColor grey: %f\t rgb:[ %f, %f, %f ]", c.grey, c.rgb[0], c.rgb[1], c.rgb[2] ) ;
}
Но, поскольку это довольно жестокий C ++, я позволил себе создать что-то немного лучше ...
struct Color final
{
double grey;
double rgb[3];
};
auto make_color ( double a, const double(&b)[3] ) { return Color { a, b[0], b[1], b[2] }; };
auto make_color ( double a, double b, double c, double d ) { return Color { a, b, c, d }; };
auto print_color ( Color c ) { printf("\nColor grey: %f\t rgb:[ %f, %f, %f ]", c.grey, c.rgb[0], c.rgb[1], c.rgb[2] ) ; }
//
int main()
{
double myRGB[3]{ 2, 6, 9 };
auto c = make_color( 10, myRGB ) ;
print_color(c);
auto z = make_color( 10, 0xFF, 0xA0, 0xB0 ) ;
print_color(z);
}
Все по старой доброй традиции: не задавайте вопросов:)
(обязательно Wandbox здесь )
ps: мне нравится ваш подход, Оливер, хотя вам, конечно, не нужны двойные скобки в этих списках инициализации.