error: switch quantity not an integer

Posted by nikeunltd on Stack Overflow See other posts from Stack Overflow or by nikeunltd
Published on 2010-12-26T23:21:06Z Indexed on 2010/12/26 23:54 UTC
Read the original article Hit count: 671

I have researched my issue all over StackOverflow and multi-google links, and I am still confused. I figured the best thing for me is ask...

Im creating a simple command line calculator. Here is my code so far:

const std::string Calculator::SIN("sin");  
const std::string Calculator::COS("cos");  
const std::string Calculator::TAN("tan");  
const std::string Calculator::LOG( "log" );  
const std::string Calculator::LOG10( "log10" );

void Calculator::set_command( std::string cmd ) {

    for(unsigned i = 0; i < cmd.length(); i++)
    {
    cmd[i] = tolower(cmd[i]);
    }

    command = cmd;
}

bool Calculator::is_legal_command() const {

    switch(command)
    {
    case TAN:
    case SIN:
    case COS:
    case LOG:
    case LOG10:
        return true;
        break;
    default:
        return false;
        break;
    }

}

the error i get is:

Calculator.cpp: In member function 'bool Calculator::is_trig_command() const':  
Calculator.cpp: error: switch quantity not an integer  
Calculator.cpp: error: 'Calculator::TAN' cannot appear in a constant-expression  
Calculator.cpp: error: 'Calculator::SIN' cannot appear in a constant-expression  
Calculator.cpp: error: 'Calculator::COS' cannot appear in a constant-expression  

The mighty internet, it says strings are allowed to be used in switch statements.

Thanks everyone, I appreciate your help.

© Stack Overflow or respective owner

Related posts about c++

Related posts about string