Why do you use typedef when declaring an enum in C++?

In C, declaring your enum the first way allows you to use it like so:

TokenType my_type;

If you use the second style, you’ll be forced to declare your variable like this:

enum TokenType my_type;

As mentioned by others, this doesn’t make a difference in C++. My guess is that either the person who wrote this is a C programmer at heart, or you’re compiling C code as C++. Either way, it won’t affect the behaviour of your code.

Leave a Comment