An unscoped enumeration defines the enumerators in the global namespace as shown below:
enum Color
{
red,
green,
blue,
};
int main(int argc, char const *argv[])
{
Color color{blue};
return 0;
}blue enumerator from enumeration Color is used without any scope resolution operator (::), although we could use Color::blue.
This property creates problems like naming collisions and polluting the global namespace.
If we want to scope them, either we can use a namespace and define them in there or use scoped enumeration. Following example shows using a namespace.
namespace Color
{
enum Color
{
red,
green,
blue,
};
}Now we have scoped Color enumerators to Color namespace.