Skip to main content
GameDev.net gamedev.net
🔒 Locked

Enum C++ way

Started by The C modest god Feb 22, 2005 at 6:23 AM 2 replies 450+ views
Original Post
The C modest god
The C modest god
How do I define and use enumrated types in C++?

typedef enum {
      D_ONE,
      D_TWO,
      D_MANY
} SimpleCount;


It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
christopherstott
christopherstott
enum SimpleCount
{
D_ONE,
D_TWO,
D_MANY
};

although the other way should work too. C++ syntax is much cleaner in my opinion. It's almost like defining a class or struct. As it should be since you're adding a new type.

Chris
doynax
doynax
Quote:
Original post by christopherstott
although the other way should work too. C++ syntax is much cleaner in my opinion. It's almost like defining a class or struct. As it should be since you're adding a new type.
The second example works in C too. An enum is a type just like in C++ (although C isn't as strict when setting enum variables to non-enumerated constants).
Syntactically enums are equivalent to structures, classes and unions in both languages. The only difference being that enum's can't be forward declared in C even though most compilers supports it as an extension.
Couvillion
Couvillion
One difference in the way C++ handles enums is that you can't iterate through them with the ++ operator, like in C. Other than that, I think they're the same, with the cleaner notation, as mentioned.
~~C--O -

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.