Possible Duplicate:
Should I use #define, enum or const?
Advantage and disadvantages of #defines vs. constants?
How enum will be more useful than #define and const.
memory and code visibilty point of view and readability point of view.
can I convert (type cast) enum to array of int, If I have taken all value within integer.
Example:
class MapPlt_clContainer {
public:
enum tagVectorType {
enVTAll = 0,
enVTPolygon,
enVTLines
}
};
tVoid MapPlt_clRender::vDrawLineClass( MapPlt_clContainer::tagVectorType* )
While calling function enum pass
vDrawLineClass( ClassArray_Group ); //Working
While calling array base address pass
int test[3] =
{
5,
6,
7,
};
vDrawLineClass( test); //Not Working
Error!!
Should it type cast it automatically? or it is compiler dependent. In my case it is giving error.
enumis a separate type unlike#defineand the language (with the help of compiler) will help you ensure you are not mixing values of different types (even if they are of the same numerical value).Additionally the value of an
enumis available to the debugger whereas the original meaning of the#defineis lost during the pre-processing time (before the code generation has even begun).Type-casting an
enumto anintis an automatic built-in process while the opposite conversion is trickier as not all theintvalues could be valid for your particularenum.Modern compilers will also warn you if you have used all the possible
enum‘s values in aswitchstatement that has nodefaultclause, something that cannot be checked for#defines