Topic: How come enum has class-wide scope ?
Author: meang@post.com (Meang Akira Tanaka)
Date: Thu, 6 Jan 2005 03:31:51 GMT Raw View
Hope this will get more attention than my previous mail about this
issue.
I have been wondering how come it has been decided that values in an
enum have to unique within a class or struct rather than only within
the enum?
Like shown in the followin example
class
{
enum type1
{
ok
};
enum type2
{
ok
};
};
Any explanation would be appreciated
thanks in advance
Meang
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: v.Abazarov@comAcast.net ("Victor Bazarov")
Date: Thu, 6 Jan 2005 06:06:29 GMT Raw View
"Meang Akira Tanaka" <meang@post.com> wrote...
> [..]
> I have been wondering how come it has been decided that values in an
> enum have to unique within a class or struct rather than only within
> the enum?
It's called "backward compatibility" IIRC.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: meang@post.com (Meang Akira Tanaka)
Date: Sat, 8 Jan 2005 21:44:08 GMT Raw View
===================================== MODERATOR'S COMMENT:
Please don't overquote. Please don't top-post.
===================================== END OF MODERATOR'S COMMENT
But haven't it been discussed whether
a) the semantic of enum should be changed so that enum values should
only be unique within the enum
or
b) proposed a new keyword which maybe could do the same as enum except
that values only have to be unique within replace the enum.
Of course there is a workaround by wrapping each enum in their own
class, but does that make sense ?
On Thu, 6 Jan 2005 06:06:29 GMT, v.Abazarov@comAcast.net ("Victor
Bazarov") wrote:
>"Meang Akira Tanaka" <meang@post.com> wrote...
>> [..]
>> I have been wondering how come it has been decided that values in an
>> enum have to unique within a class or struct rather than only within
>> the enum?
>
>It's called "backward compatibility" IIRC.
>
>
>---
>[ comp.std.c++ is moderated. To submit articles, try just posting with ]
>[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
>[ --- Please see the FAQ before posting. --- ]
>[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: v.Abazarov@comAcast.net ("Victor Bazarov")
Date: Sun, 9 Jan 2005 01:47:50 GMT Raw View
"Meang Akira Tanaka" <meang@post.com> wrote...
> But haven't it been discussed whether
>
> a) the semantic of enum should be changed so that enum values should
> only be unique within the enum
I don't remember such discussion. If it existed, Google probably has
a record of it.
In any case, I personally do not agree with that. I suspect that I am
not alone.
> or
>
> b) proposed a new keyword which maybe could do the same as enum except
> that values only have to be unique within replace the enum.
New keywords are _really_ hard to introduce without breaking existing
code.
> Of course there is a workaround by wrapping each enum in their own
> class, but does that make sense ?
Since there are work-arounds certain problems, it is very unlikely the
language is going to change to accommodate a whim or two.
> [..]
Victor
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: brangdon@cix.co.uk (Dave Harris)
Date: Sun, 9 Jan 2005 18:51:23 GMT Raw View
meang@post.com (Meang Akira Tanaka) wrote (abridged):
> But haven't it been discussed whether
>
> a) the semantic of enum should be changed so that enum values should
> only be unique within the enum
Many times. Either here or in comp.lang.c++. The semantics would be
similar to putting the enum in its own namespace, then adding a using
declaration for that namespace to get the names out again. I don't recall
seeing an argument against this, but it's not a high priority for most
people either.
-- Dave Harris, Nottingham, UK
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]