Re: Can I refer to members of an enumeration without using ::?
From: Swampmonster (swampmonster_at_der-ball-ist-rund.net)
Date: 12/14/04
- Next message: Swampmonster: "Re: Small dynamic objects and performance degradation."
- Previous message: Swampmonster: "Re: C++ inlining as a multithreading optimization tecnique?"
- In reply to: Howard: "Re: Can I refer to members of an enumeration without using ::?"
- Next in thread: msalters: "Re: Can I refer to members of an enumeration without using ::?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 14 Dec 2004 02:44:35 +0100
Howard wrote:
> "Xenos" <dont.spam.me@spamhate.com> wrote in message
> news:cpkmpd$9o02@cui1.lmms.lmco.com...
>
>>"Xenos" <dont.spam.me@spamhate.com> wrote in message
>>news:cpkgt0$9o01@cui1.lmms.lmco.com...
>>
>>>"Howard" <alicebt@hotmail.com> wrote in message
>>>news:oejvd.1086496$Gx4.129954@bgtnsc04-news.ops.worldnet.att.net...
>>>
>>>>But yes, it's legal C++. The name of an enumeration is not required
>>>>for
>>>>resolution, except in cases where you have members of different
>>>
>>>enumerations
>>>
>>>>having the same name. Such as:
>>>>
>>>>enum enumABC { eMin, eA, eB, eC, eMax };
>>>>enum enumXYZ { eMin, eX, eY, eZ, eMax };
>>>>
>>>>In that case, you'd need to specify which enumeration you were
>>>>referring
>>>
>>>to
>>>
>>>>(when referring to eMin or eMax). (But in such a case, putting them in
>>>>separate namespaces is also probably a good idea.)
>>>>
>>
>>I just tried defining the above enums in a test program, and g++
>>complained
>>because they contained the same identifier names for the elements. It
>>this
>>really legal?
>
>
> Apparently I was mistaken on this point. When both names are visible in the
> current scope(s), this would amount to illegal name overloading, and won't
> compile. They'd have to be in different namespaces (also, I think, within
> separate classes would work?)
>
> So my example won't compile. If, however, enumXYZ was in namespace nsXYZ,
> then you could use it by specifying nsXYZ::eMin, for example, (which is what
> I suggested was probably better to do anyway). But you don't have to
> specify the name of the enumeration in order to access its members. This
> fact (that the names of the members are not restricted to having the enum
> type itself specified) is exactly what makes it illegal to have the same
> member name in multiple enums in the same scope: both names are visible at
> the scope level, and therefore you can't have two of them declared there!
>
> Sorry about that!
>
> -Howard
>
AFAIK you can't even qualify a "member of an enum" (correct term?
"enumerator"?) with the enum's name :-)
bye,
'monster
- Next message: Swampmonster: "Re: Small dynamic objects and performance degradation."
- Previous message: Swampmonster: "Re: C++ inlining as a multithreading optimization tecnique?"
- In reply to: Howard: "Re: Can I refer to members of an enumeration without using ::?"
- Next in thread: msalters: "Re: Can I refer to members of an enumeration without using ::?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|