Recommended Posts

OK, I think I know the answer to my problem, and it is "no", but I'll see if I am wrong.
In C++ enums don't get their own namespace, so you can easily have name collisions. Is there a cleaner way of doing than this, for example:

namespace Day{
enum Day{Monday, Tuesday};
}

That puts it in its own namespace, but then whenever I want to make a Day, I have to say "Day::Day". Is there a way to make only the constants in their own namespace, while still using enums?
[edited by - PlayGGY on March 17, 2004 7:43:22 PM]

Share this post

Link to post

Share on other sites

That''s what I thought initially, but is this really going to behave like an enum? Even though there are conversions both ways, it seems like somewhere in a dark corner of the Standard, there ought to be a rule that will break your construction.

Anyway, if using Day::Day works, that''s the perfect solution IMO.

0

Share this post

Link to post

Share on other sites

quote:Original post by Cedric That''s what I thought initially, but is this really going to behave like an enum? Even though there are conversions both ways, it seems like somewhere in a dark corner of the Standard, there ought to be a rule that will break your construction.

It seems to work for me. I have a project filled with such hackish namespaced-enumerations (and something similar for namespaced-bit-masks) and haven''t had any problems.