C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How come enum has class-wide scope ?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Meang Akira Tanaka
Guest





PostPosted: Thu Jan 06, 2005 3:31 am    Post subject: How come enum has class-wide scope ? Reply with quote



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 ]

Back to top
Victor Bazarov
Guest





PostPosted: Thu Jan 06, 2005 6:06 am    Post subject: Re: How come enum has class-wide scope ? Reply with quote



"Meang Akira Tanaka" <meang (AT) post (DOT) com> wrote...
Quote:
[..]
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 ]


Back to top
Meang Akira Tanaka
Guest





PostPosted: Sat Jan 08, 2005 9:44 pm    Post subject: Re: How come enum has class-wide scope ? Reply with quote




===================================== 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, [email]v.Abazarov (AT) comAcast (DOT) net[/email] ("Victor
Bazarov") wrote:

Quote:
"Meang Akira Tanaka" <meang (AT) post (DOT) 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 ]


Back to top
Victor Bazarov
Guest





PostPosted: Sun Jan 09, 2005 1:47 am    Post subject: Re: How come enum has class-wide scope ? Reply with quote

"Meang Akira Tanaka" <meang (AT) post (DOT) com> wrote...
Quote:
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.

Quote:
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.

Quote:
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.

Quote:
[..]

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 ]


Back to top
Dave Harris
Guest





PostPosted: Sun Jan 09, 2005 6:51 pm    Post subject: Re: How come enum has class-wide scope ? Reply with quote

[email]meang (AT) post (DOT) com[/email] (Meang Akira Tanaka) wrote (abridged):
Quote:
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 ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.