Archived

This topic is now archived and is closed to further replies.

enums

This topic is 5277 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

enum Status{ Fail = 0, Pass = 1 }; ... Status s; s = Status:: Pass; ... Can someone tell me why this isnt working in VC. I have made it work in the past, I'm just confused when it returns an error saying that Pass is not a member of Status. ( disregard the space after Status:: )

Share on other sites
i found adding a typedef before the enum keyword helps, but maybe thats just for my particular situations.

-J

Share on other sites
Oh, and you don't need the Status:: bit just this:

s = Pass;

-J

[edited by - jason2jason on July 6, 2003 2:02:04 PM]

Share on other sites
Thanks for the help. Whenever something in c++ doesnt feel like working, I just want to start throwing stuff. This time my monitor has been saved. ;-)

enum {
Fail = 0,
Pass
} Status;

Share on other sites
quote:

Whenever something in c++ doesnt feel like working, I just want to start throwing stuff.

Yeah I know the feeling. I've gotten over it by realising that its almost always oneself that's at fault and getting stressed out is a very ineffective way of solving such problems. Also just imagine what a fit babe would think if she was watching you thrash about like a baby.

[edited by - barn door on July 6, 2003 6:38:58 PM]

Share on other sites
Actually is there a way so that you can use Status:: without actually putting it as a static member in a structure?

Share on other sites
Unfortunately, not with Visual Studio (event 2003). However, it is covered by the standard.

Share on other sites
quote:
Original post by antareus
Actually is there a way so that you can use Status:: without actually putting it as a static member in a structure?

Hmm...
#define Status Status::Xnamespace Status {enum X {Fail, Pass};  // First one starts out as zero (I believe that's guaranteed)}

I think that should work.

[EDIT] Whoops, I got the enums backwards
[EDIT2] Crap, you lose the declaration capability.
[EDIT3] I think I figured it out...maybe
[EDIT4] There I made a proper hack out of it

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________

[edited by - Thunder_Hawk on July 6, 2003 10:28:09 PM]

[edited by - Thunder_Hawk on July 6, 2003 10:38:19 PM]

Share on other sites
Actually, I have done it before. In my code it seems that when the enum is inside of a class, doing "Class::Status::OK" actually works. But then when I put the enum into a namespace or just global and not encapsulated anywhere I get the "not a member of" error. Very strange if you ask me, and it simply doesnt make sense. I guess its one of those quirks you get with VC. You kinda learn to live with it and try out a different way to do things. Which really sucks sometimes:-P

Share on other sites
It's a shame, C#'s method of forcing you to append the enum name to the front is nice.

I'll get on the VC++ newsgroups and ask about it later on.

Edit: also, I've noticed you can't even forward declare enums. I can't see why though, enums are just converted to ints.

[edited by - antareus on July 7, 2003 9:44:10 AM]

Share on other sites
quote:
Original post by Thunder_Hawk
#define Status Status::Xnamespace Status {enum X {Fail, Pass};  // First one starts out as zero (I believe that''s guaranteed)}

jesus christ, that is the most hack-a-rific thing I''ve seen in a while.

Share on other sites
quote:
Original post by Thunder_Hawk
#define Status Status::Xnamespace Status {enum X {Fail, Pass};  // First one starts out as zero (I believe that''s guaranteed)}

er.... which would preprocess to:

namespace Status::X {enum X {Fail, Pass};}

No points for guessing whether that compiles.

How appropriate. You fight like a cow.

• Forum Statistics

• Total Topics
628750
• Total Posts
2984498

• 12
• 25
• 12
• 10
• 17