I’m trying to create a class for colors. Something like:
class Color
{
public:
float r, g, b, a;
Color(float r_, float g_, float b_, float a_);
...
}
And for convenience I would like to include instances of the class as part of the class so that I don’t need to specify the rgba values for common colors as such:
image.setPixel(100, 100, Color::Red);
However, I don’t know what the correct syntax for this is. I’ve been searching on Google for a while and I haven’t been able to find the term for this method :(. I’ve seen it done in other libraries before, so I think it’s possible. I’m thinking it has to be declared as a static constant, but I’m not sure about this:
class Color
{
public:
static const Color Red;
...
}
const Color::Color Red = Color(255, 0, 0, 255);
But I get an
error saying Color::Color is an invalid type
What am I doing wrong?
Red is the member, it should be: