3
Well I’m having a doubt I’m starting now at C++
I’m using an Enum class:
enum class TYPE_ENTER {
ENTER_OK = 0x1,
ENTER_WARNING = 0x2
};
but when I compile the function there is error C2678 in the function.
int EnterSession::CheckEnter(char *type, int id) {
if (*(int*)type == TYPE_ENTER::ENTER_OK) {// Ocorre Erro em ==
//Mycode
}
return 0;
}
At compile time error occurs in ==, it is possible to maintain Enum class or I will have to use Enum normal ?
just to understand, if it were me to convert the type instead of Enum how would it look ? I tried using
TYPE_ENTER TestType = (int)type;
most occurs C2440– carolzinha
Friend, as you are casting to int, the Testtype should be INT and not TYPE_ENTER. You cannot compare an int type with an ENUM CLASS without casting.
– Paulo Victor
If
char *type
do not point to an object of the typeint
, the expression*(int *)type
results in undefined behavior.– Mário Feroldi
The response was corrected with the appropriate tests done.
– Paulo Victor