C ++ 11
This answer was originally written in 2011. Now that C ++ 11 support is widely available, the preferred way is to use the enum class as follows: Matthew D. Scholefield:
enum class Player { User, Computer };
Enumerated constants must be specified with the name of the enumeration when referenced (for example, Player::Computer ).
Before C ++ 11
No, there is nothing wrong with the fact that the listing is public. However, keep in mind that the constants listed cannot be qualified with a type name enum enum. That is, you cannot write Player::USER or similarly to refer to the constant USER ; they appear directly in the encompassing namespace. Thus, it might be a good idea to set a prefix for your constants so that no name clashes occur.
For example, consider the following declaration:
enum Player { PL_USER, PL_COMPUTER }
This is safer because name collisions are much less likely with the prefix "PL_". In addition, it improves the readability of the code, hinting at which variable this constant belongs to.
Languages like C # and Java have taken a slightly different approach to enumerations, where you need to specify both the enumeration name and the name of the constant, for example Player.USER . A similar effect can be achieved in C ++ by embedding an enum declaration in its own namespace. For instance:
namespace Player { enum Type { USER, COMPUTER } }
This results in embedding PLAYER and COMPUTER in the PLAYER namespace instead of the global (or nested) namespace. Whether this is a good approach or not is, in my opinion, a matter of preference.