@JM are you going to have facility to deal with enums (amongst all the other things) in your scripting / interpreter / child language or whatever it is you are trying to do? That is, once you have learnt what they are, and why you don't use #define.
As firedraco has already said, it is not a good idea to cast an int to an enum as you can end up with a meaningless value.
It would better to use a helper function to do the conversion, so that meaningless values can be ignored (you return a default value) or you report an error.
e.g. where the method is declared in Class as:
static Enum IntToEmum(int Type);
it could be
1 2 3 4 5 6
Class::Enum Class::IntToEmum(int Type){
// if enum is contiguous
if((1 <= Type) && (Type <= 3))
returnstatic_cast<Enum>(Type); // new-style C++ casts are better
return A; // return default value if int value is invalid
}
or
1 2 3 4 5 6 7 8 9 10
Class::Enum Class::IntToEmum(int Type){
// handles non-contigous case, e.g. Enum {A = 1, B = 3, C = 5};
switch(Type) {
case A: return A;
case B: return B;
case C: return C;
default {/* do nothing */}
}
throw invalid_enum(); // throw an exception
}