enum
enum
In C++, enum signifies a slightly stronger type than in C, because C++ do type checking.
For example, in C, one could write:The way enum variable declared is different in C & C++, the key word enum is not required in C++.
enum Direction { UP, DOWN };
Direction d = 1;
In C++, this would be illegal, only UP or DOWN can be assigned to a variable of type Direction, though there is still implicit casting to integer, so one could still write:
int i = UP;
In C, once the enum was declared as above, declaring variables of type Direction would have to be done through the enum keyword, like this:
enum Direction d = UP;
In C++, the name "Direction" becomes a type in itself, so you can write:
Direction d = UP;

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home