Hello,
Simple question. I would like to confirm something about enum types. I always thought that when assigning a value from one variable type to another, a cast is required unless its an implicit cast:
http://www.cplusplus.com/doc/tutorial/typecasting/
I was just wondering if assigning one enum parameter of type A to another enum variable of type B is considered an implicit cast aswell?
If I do this, I don't seem to get any compile errors and yet an assignment is made between two different types:
Code:
#include <stdio.h>
enum A{one=1, two, three};
enum B{Dog =100, cat, bird};
int main()
{
enum B x;
x = one;
}
The reason I ask is that I am doing this sort of stuff lately where enums are assigned to each other and they are of different types.
In conclusion, I would like to know as to why the above works... is it because enum types are implicit and a cast is done automatically for us... or is it that because by nature enums are of int type and there really is no need for casting them. Also, it happens that I assign an enums value to a short... and that works as well? In reference to above code.. like this:
unsigned short s;
s = one;
In my code project, everything works, but I am being ignorant as to what is really happening. I am sort of just brushing it under the carpet so of speak. And thats no good. I apologize for the simple question. Any feedback is much appreciate.
Rob