Now that you understand the difference, from the answers above, I'd like to point out a couple of places where the "new" way of doing things breaks down, and what you can do about it.
Consider this (abbreviated) actual example I ran into, porting some audio software I wrote in C to modern C++ (C++17):
typedef enum sample_type_e {
sample_type_uint16,
sample_type_double
}sample_type_t;
Now, the first thing to know is that the typedef here is no longer required; you can read more about that elsewhere. Moving on...
This code, compiled in Visual Studio 2019, will result in the error you describe.
Now, one approach to fixing this would seem to be to move to the new syntax-- but watch what happens:
enum class SampleType {
uint16,
double
}
Oops.
That's not going to work-- double is a reserved word. Now, you could, in exasperation, do this:
enum class SampleType {
uint16,
type_double
}
...but that's not very consistent, and by the time you get to this:
enum class SampleType {
type_uint16,
type_double
}
...you have arguably achieved the exact opposite of at least one of the purported benefits of this new feature: being terse, where possible, without losing context.
The nuisance in my supposedly-contrived but actually real-world example is that you can't scope a reserved word: they're always reserved. (Tangent point of interest: there are languages where that is never true...)
This is called "being unlucky"; it happens a lot more often than language designers like to admit, and it always comes up when you don't have one of them in the room with you.
So, if something like that happens to come up for you, and you just really don't like what the results of trying to use "class enum" wind up looking like, what do you do?
Well, it turns out you can probably make the entire original problem go away by using another language feature that is considered good practice to use wherever possible: namespacing. If I merely namespace that original declaration (minus the crufty typedef), I get:
namespace audiostuff {
enum sample_type_e {
sample_type_uint16,
sample_type_double
};
};
...and as long as any code using that stuff is either in the same namespace, or has
using namespace audiostuff;
at the top, or, alternately, uses is like this:
audiostuff::sample_type_e my_sample_type_var;
...then, lo and behold, Visual Studio stops complaining-- and other compilers should as well.
The complaint, after all, is about reminding you that you should avoid cluttering up the global namespace-- especially by accident. "class enum" is one way to do that, but using an explicit namespace is as well.