samedi 26 novembre 2022

Basic types say `uint8_t` could be inherited? [duplicate]

Here is the simple code snippet which works well:

#include <iostream>

enum class Color : uint8_t {
    Blue = 1,
    Red = 2,
};

std::ostream &operator<< (std::ostream& os, const Color& color)
{
    switch(color)
    {
        case (Color::Blue):
        {
            os<< "blue";
            break;
        }
        case (Color::Red):
        {
            os << "red";
            break;
        }
        default:
        {
            break;
        }
    }

    return os;
}

int main()
{
    std::cout << Color::Blue << std::endl;
}

And the aforementioned code snippet is seen from this more complicated one.

My question is whether basic types say uint8_t could be inherited or not.

Aucun commentaire:

Enregistrer un commentaire