Razmig said:
Dear mates,
This is just a small survey for the common (and uncommon) nontrivial
uses of the aforementioned C++ construct.
It's posted by an average C++ programmer who's curious about how his
elder colleagues utilize this feature of C++ in their implementations
based on diverse programming styles in diverse application domains.
Thank you for your interest.
Best regards,
//rk
I used to use enums to declair methods only capable of accepting or
returning certaing integer values. It really become more pain than it
is worth most of the time in many of the applications I put it to; plus
I am not too sure it actually works that way
Mainly now I just use enums to declair sets of constants that I want to
be distinct, many of which are used as induces to arrays. For instance
I use two enums in the interface to my Board class in a chess engine I
am working on:
enum { red, black }
enum { empty, all = 0, pawn, canon, cart, horse, elephant, guard, general };
pawns = boardInstance[red][pawn]; // returns the red pawn board.
and so on...
Things like that make my code more pleasant, and it needs things like
that
I also use it to refer to things that don't necissarily have to be in
any order, or even next to each other, but must be distinct and/or are
related in idea. For instance, my interface modes are specified in an
enum; not because they care what the numbers are, but because they are
related and it groups symbols for readability...and there is a lot less
typing than with a bunch of #defines.
NR
PS. No, I am not an "elder" programmer. Especially with C++ as I have
been more of a C or Objective-C man in the past. And yes, that is a
pretty trivial use