I was working on creating a multilevel enum for a Library.
- I would like something (not necessarily exactly) like this:
Book::Category::PROGRAMMING::C_PLUS_PLUS
where Book
is a struct
and Category
is (currently) an enum class
.
Basically, I would like to nest enums.
I know that I can just do:
Book::Category::PROGRAMMING_C_PLUS_PLUS
But not only will this create a long list of values in Category
, but will make maintaining it a nightmare (I tried to do this with 30, and it was already a headache).
I want to divide and conquer this problem.
Edit 1: The reason I didn't want it to be a std::string
is that it's value can be anything and everything. I wanted to constrain the domain of Category
.
And no, PROGRAMMING
is not a major part of my Library. Let me try with classes and inheritance.
Basically, the reason I wanted enum
s was to have a fixed set of valid constants.
References:
- Can enum class be nested?
-> I need to create objects of
Book
, and hence it cannot be a namespace. I couldn't understand the answer that used templates. - Why is enum class preferred over plain enum? -> Has no answer to my question.