I haven\'t written any C++ in years and now I\'m trying to get back into it. I then ran across this and thought about giving up:
typedef enum TokenType
{
Holdover from C.
The actual answer to the "why" question (which is surprisingly ignored by the existing answers top this old question) is that this enum
declaration is probably located in a header file that is intended to be cross-compilable as both C and C++ code (i.e. included into both C and C++ implementation fiules). The art of writing such header files relies on the author's ability to select language features that have the proper compatible meaning in both languages.
In some C codestyle guide the typedef version is said to be preferred for "clarity" and "simplicity". I disagree, because the typedef obfuscates the real nature of the declared object. In fact, I don't use typedefs because when declaring a C variable I want to be clear about what the object actually is. This choice helps myself to remember faster what an old piece of code actually does, and will help others when maintaining the code in the future.