answersLogoWhite

0

That is correct - In c plus plus you cannot assign integer value to enum - You can only assign an enum value to an enum.

Even though an enum looks like an integer, it is not. It is an enum, and C++ implements strict type checking to reduce the probability of bad programming practices.

enum ColorCode {black, brown, red, orange, yellow, green, blue, violet, grey, white};

ColorCode myColorCode;

myColorCode = yellow;

Even though yellow has an integer value of 4, you cannot say myColorCode = 4.

User Avatar

Wiki User

∙ 16y ago
User Avatar

What else can I help you with?

Continue Learning about Engineering

How would you write a program that read an integer for display each of digit of integer in English?

Use an enum if you are using a c style language. Or a map data structure. Assign each integer an English value and then match it to what the user inputs.


What is a enumerated data type?

An enumerated data type is a manufactured data type. The orginal implementation of the boolean data type was an enumerated type. enum boolean {true, false}; this creates a type : boolean and two constants of type boolean: true and false. true has an integer value: 0 false as an integer value: 1 The way boolean is now implemented in C and C++ and C# maintains the convention that 0 is true. A common use of enumerated types is in game programming. You can enumerate the cardinal directions, for example, north, east, south, west, so that you can turn right by performing: enum compass {north, east, south, west}; compass direction = west; direction = (direction + 1) % 4 // at this point, direction would be equal to north, or 0


Which datatype cannot be checked in switch case?

enum


Difference between enum and const in c?

members in union and enum both shares memory and the size of the union is the size of the highest element like if there is one int and one char in union then the size of union will be the size of an int. if an int and an float are there then the size of the union will be the size of the float. This is not the case in the enum. it has similar type of members. and the value of the members can be assign manually like this enum e{ZERO,ONE,TWO=20,THREE}; here ZERO will have value 0, ONE will have value 1, TWO will be having 20 , THREE will be having 21.. and so on Answer: they are no way similar, no point in comparing them.


Enum in java?

Enum in java is a keyword which is introduced in JDK 1.5 and its a type like Interface and Class.Enum constants are implicitly static and final and you can not change there value once created. Enum in Java provides type-safety and can be used inside switch statment like int variables. Since enum is a keyword you can not use as variable name and since its only introduced in JDK 1.5 all your previous code which has enum as variable name will not work and needs to be refactored.

Related Questions

How would you write a program that read an integer for display each of digit of integer in English?

Use an enum if you are using a c style language. Or a map data structure. Assign each integer an English value and then match it to what the user inputs.


Why is an enumeration?

An alternative method for naming integer constants is often more convenient than 'const' . This can be achieved by using keyword enum. for example : enum { START , PAUSE , GOO };


What is a enumerated data type?

An enumerated data type is a manufactured data type. The orginal implementation of the boolean data type was an enumerated type. enum boolean {true, false}; this creates a type : boolean and two constants of type boolean: true and false. true has an integer value: 0 false as an integer value: 1 The way boolean is now implemented in C and C++ and C# maintains the convention that 0 is true. A common use of enumerated types is in game programming. You can enumerate the cardinal directions, for example, north, east, south, west, so that you can turn right by performing: enum compass {north, east, south, west}; compass direction = west; direction = (direction + 1) % 4 // at this point, direction would be equal to north, or 0


What is enum in c sharp?

Enum in C#, most of time, are used to defined integer-based values in symbolic ways.Example - exiting or return codesTraditionally, when a program exits, it may return an integer value to indicate the status of the execution.0 everything is OK1 Something was wrong, but not fatal2 Fatal Errorpublic enum ExitCode {OK = 0, Warning = 1, FatalError = 2}... return ExitCode.OK; // old way would by return 0; and one would need to know 0 stands for


Which datatype cannot be checked in switch case?

enum


Difference between enum and const in c?

members in union and enum both shares memory and the size of the union is the size of the highest element like if there is one int and one char in union then the size of union will be the size of an int. if an int and an float are there then the size of the union will be the size of the float. This is not the case in the enum. it has similar type of members. and the value of the members can be assign manually like this enum e{ZERO,ONE,TWO=20,THREE}; here ZERO will have value 0, ONE will have value 1, TWO will be having 20 , THREE will be having 21.. and so on Answer: they are no way similar, no point in comparing them.


What is Enum and why use in your program?

The enum keyword provides a handy way to create a sequence of integer constants in a concise manner. Optionally the declaration can include a name for the sequence after the enum keyword. The constant names follow with a comma and placed within braces. The name assigned can be used to call the function again at later stage. The constants can be assigned any individual value but the following constant will always increment it by one.


Why do you have enumeration?

There are different methods for naming a integer constant, one such method is enumeration. Enumeration is created by using the keyword enum.


Enum in java?

Enum in java is a keyword which is introduced in JDK 1.5 and its a type like Interface and Class.Enum constants are implicitly static and final and you can not change there value once created. Enum in Java provides type-safety and can be used inside switch statment like int variables. Since enum is a keyword you can not use as variable name and since its only introduced in JDK 1.5 all your previous code which has enum as variable name will not work and needs to be refactored.


What is the underlying type of an enum declaration that does NOT explicitly define an underlying type?

In C#, if an enum declaration does not explicitly define an underlying type, it defaults to int. This means that the first enumerator has a value of 0, and each subsequent enumerator's value is incremented by one. For example, in an enum without an explicit underlying type, the first member would be 0, the second would be 1, and so on.


What is difference between C enum and C plus plus enum?

In C++, enum signifies a slightly stronger type than in C. For example, in C, one could write: 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; Another difference has to do with the way variable are declared in general in C++. 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;


Why enum data type cannot be checked in switch case?

It should work... perhaps you made some mistakes.