you cannot.
enums are integers. You can make a 4 byte integer hold the 3 bytes if that is useful.
you can do something similar to this (syntax may be wrong)
Vector3f[] colors = {{255,0,0},{0,0,255}, ... }etc
and an enum
{
red,green,blue,max;
};
and do this
colors[red];
but that does not really seem to be any more elegant here.
you can also get rid of the #defines and just make constant globals:
const Vector3f STANDARD_RED_COLOR (255, 0, 0); //cleaner than #define.
I highly recommend doing it this way, instead of #defines. There are multiple reasons including ease of debugging.
As a variant to @JLBorges, I would prefer to do this:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <cstdint>
struct color {
uint8_t r, g, b;
staticconstexpr color red() { return {255, 0, 0}; }
staticconstexpr color green() { return {0, 255, 0}; }
staticconstexpr color blue() { return {0, 0, 255}; }
};
int main() {
auto r = color::red();
}
I'd prefer to keep the predefined colors in the color class, but then the problem with using static variables becomes struct literals from within the struct, which cannot occur. You would have to put them in another class or just constants hanging around in the namespace. However, putting them into a constexpr function allows you to return color literals.