I'm getting an error concerning enum (I think)

前端 未结 4 1983
粉色の甜心
粉色の甜心 2020-12-20 16:41

I\'m testing code remotely on a Solaris machine through SSH Secure Shell using c++. Not sure of what version anything is; Solaris, the c++/compiler, etc. (and don\'t know ho

相关标签:
4条回答
  • 2020-12-20 16:57
    enum STR_TO_INT_STATUS { SUCCESS, OVERFLOW, UNDERFLOW, INCONVERTIBLE };
    

    Perhaps on of the enumerators like SUCCESS was already previously defined. Try using SUCCESS_TEST or something to verify this.

    Edit

    Another way to verify this is to compile the code with the -E option, this shows the preprocessor output. For example: gcc -E main.cpp

    0 讨论(0)
  • 2020-12-20 17:05

    My guess is that either <limits> or <cmath> have defines for one or more of SUCCESS, OVERFLOW, UNDERFLOW, INCONVERTIBLE, which causes your enum identifiers to be converted to "numeric constants", which in turn would cause the errors that you are seeing.

    You don't see them in the first version because you didn't include those headers.

    Simple way to check: Try renaming the enum identifiers.

    0 讨论(0)
  • 2020-12-20 17:09

    The include of cmath is defining preprocessor constants OVERFLOW as 3 and UNDERFLOW as 4. So the line declaring the enum becomes (if there are no other constants):

    enum STR_TO_INT_STATUS { SUCCESS, 3, 4, INCONVERTIBLE };
    

    which, of course is not valid syntax.

    0 讨论(0)
  • 2020-12-20 17:12

    I think it's the following line:

    int size_of( int );
    

    ...should be something more like:

    int sizeOfInt = size_of( int );
    

    edit

    I just compiled it on my machine and it's your OVERFLOW definition... #define's are evil!

    Try this:

    enum STR_TO_INT_STATUS { STR_TO_INT_SUCCESS, STR_TO_INT_OVERFLOW, STR_TO_INT_UNDERFLOW, STR_TO_INT_INCONVERTIBLE};
    
    0 讨论(0)
提交回复
热议问题