IMHO, enums should always be contained by a class or namespace. Otherwise, you will have name conflicts just like you get between other types of identifiers. In other words, instead of:
Code:
enum CarModel
{
Toyota,
BMW,
Ford
};
class Car
{
public:
Car(CarModel model_p) : model(model_p) { }
private:
CarModel model;
};
You should instead place the enumeration inside the class:
Code:
class Car
{
public:
enum Model { Toyota, BMW, Ford };
Car(Model model_p) : model(model_p) { }
private:
Model model;
};
This way, external code will refer to Car::Toyota instead of just Toyota. If the enumeration is conceptually a part of a class, or used to describe objects of a class, then it should be contained in the class.
A "bare" enumeration which is not closely related to any single class should at least go into a namespace, not the global namespace. For instance declaring an enum with values Yes, No, Maybe is highly likely to conflict with some other enumeration.