A good way to declare C ++ enumerations without bloating the namespace

I noticed that if I do something similar in C ++ using Microsoft Visual Studio Express 2013:

namespace LogLevelEnum { enum Type { ALL, FINEST, FINE, INFO, WARNING, SEVERE, OFF }; } typedef LogLevelEnum::Type LogLevel; 

I can access enum elements using things like LogLevel::INFO and LogLevel::WARNING , but not just using INFO or WARNING . I like it because it doesn't put as many characters in the covered namespace.

However, I was wondering if this is standard behavior. I know that classes and namespaces can be indexed using the :: operator, but this makes little sense for working with enumerations, as they simply reset everything in the namespace.

+5
source share
1 answer

However, I was wondering if this is standard behavior.

Yes, if you use a compiler compatible with C ++ 11, and by standard you are referring to the C ++ 11 standard.

but not just using INFO or WARNING.

This is because the enumeration is in the namespace area. Have you tried LogLevelEnum ::INFO or LogLevelEnum ::WARNING ?

A good way to declare C ++ enumerations without bloating the namespace

Use Cloud enumeration areas , i.e. enum struct | class enum struct | class instead of enum , defining an enumeration.

+4
source

All Articles