当我有一个与当前类中使用的值相同的枚举时,如何使用另一个类中的枚举? C ++

时间:2020-11-03 01:27:35

标签: c++ enums

我在返回一个函数时遇到了麻烦,该函数要求我从第一类返回枚举“ BEGIN”。我遇到的问题是我正在使用的当前类中使用单独的枚举列表。因此,当我返回函数时,它是从当前类而不是派生类中获取的。有人知道怎么修这个东西吗? 标头类:

enum Token {
    PRINT, BEGIN, END, IF, THEN}
LexItem(Token token, string lexeme, int line) {
        this->token = token;
        this->lexeme = lexeme;
        this->lnum = line;
    }

功能类别:

LexItem getNextToken(istream& in, int& linenum){
enum TokState { BEGIN, INID, INSTRING, ININT, INREAL, INCOMMENT, SIGN }
if(lexeme.compare("begin")){
   LexItem item = LexItem(BEGIN, lexeme, linenum); //error on LexItem no instance of constructor
   return item;}

我认为这是因为它使用的是TokState begin,而不是Token中的那个。不知道如何解决。我无法在任何一个类中更改枚举。

0 个答案:

没有答案