While tying my hands on enum
I found that:
enum
can't be assigned any literal (even of integral types).enum sign{alpha,beta}; alpha=4; //error: lvalue required as left operand of assignment
Regarding this I can't understand how enum
is not a lvalue since it has a name (identifier).
- In C++ Primer it has been given that:
An object of enumeration type may be initialized or assigned only by one of its enumerators or by another object of the same enumeration type.
It has also shown in an example that:
enum p1{var1A,var1B};
enum p2{var2A,var2B};
var2A=var1A //Error: var2A is not a p2 enumerator -> as written in the book
var2A=var2B //Correct as per the book
But why on assigning the correct value all I am getting is the same lvalue
error which is being shown in point 1.