Is there a point of doing somthing like this:
namespace status{
enum status{
ok,
error
};
}
and use it like that status::ok
Or should i do this:
enum status{
status_ok,
status_error
};
and use it like this status_ok?
Update:
With C++11 you now should do this:
enum class status {
ok,
error
};
and use like this: status::ok
I personally don’t like the second variation because the
status_part seems redundant to me. The former version avoids that problem, but having a typestatus::statuslooks strange too. Furthermore, a namespace is open to modification, so in case somebody did something likeYou would get a compiler error since the function
errorclashes with yourenumvalue.I prefer to use a third variation:
This lets me write functions like