Given a toy struct
with a default constructor like this one:
struct RGB {
unsigned char r, g, b;
RGB()
:r(0), g(0), b(0) {}
};
How do I initialise one to a specific colour, assuming I don't have access to the source code to add my own constructor.
I don't understand fully why these don't work:
// OK, I can sort-of accept this one
RGB red = {255, 0, 0};
// Not shorthand for green.r=0, green.g=255, green.b=0;?
RGB green = {.r = 0, .g = 255, .b = 0};
// I seem to be missing a constructor that accepts a list?
RGB blue{0, 0, 255};
Is there any other C++11 way to shorten the good old-fashioned:
RGB yellow;
yellow.r = 255;
yellow.g = 255;
yellow.b = 0;
Furthermore, how could I minimally modify the struct
declaration to support any of the above, as well as having a default initialisation method.