c++ – Enum class not accepting check


Well I have a question I'm starting now in C++

I'm using an enum class:

enum class TYPE_ENTER {
    ENTER_OK = 0x1,

but when I compile the function, error C2678 occurs in the function.

int EnterSession::CheckEnter(char *type, int id) {

    if (*(int*)type == TYPE_ENTER::ENTER_OK) {// Ocorre Erro em ==
    return 0;

When compiling, error occurs in == , is it possible to keep the enum class or will I have to use normal enum ?


You must either cast your enum class to INT too, or else cast the variable type to the type of your enum class, and you are casting the wrong one.

To convert string or char to INT, you must use the atoi() function;

The code would look like this:

    int nType = atoi(type);

    std::cout << nType;
    if (nType == (int) TYPE_ENTER::ENTER_OK) {
Scroll to Top