相关疑难解决方法(0)

错误:切换数量不是整数

我已经在StackOverflow和多谷歌链接上研究了我的问题,我仍然感到困惑.我认为对我来说最好的事情就是问...

我创建一个简单的命令行计算器.到目前为止,这是我的代码:

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;
    }

}
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

Calculator.cpp: In member function 'bool Calculator::is_trig_command() const':  
Calculator.cpp: error: switch …
Run Code Online (Sandbox Code Playgroud)

c++ string switch-statement constant-expression

10
推荐指数
2
解决办法
7万
查看次数