samedi 19 octobre 2019

How to design a colour class that has already-defined standard colours in the most elegant c++ way?

How to design a Colour class that has already defined the standard colours in the modern elegant c++ way? I would like to know a minimal example design that does so instead of a complete colour class.

I have the basic Colour class:

class Colour
{
    public:
    double rgb[3];
};

Now I can use it in the following way:

Colour c1 = {1.0, 0.0, 0.0}, c2 = {1.0, 1.0, 0.0};

But since there are already standard colours very common to us that we will always like to use something like the following:

Colour c1 = Colour::Red, c2 = Colour::Yellow;

How to achieve the above?

Advance thanks.

Aucun commentaire:

Enregistrer un commentaire