我有一个名为 TokenType 的枚举类型,如下所示:
#ifndef TOKENTYPE_H_
#define TOKENTYPE_H_
class TokenType{
public:
enum TType{
INTEGER,
IDENTIFIER,
PRINT,
READ,
SIGN_PLUS ='+',
SIGN_MINUS ='-',
SIGN_DIV ='/',
SIGN_MUL ='*',
SIGN_LESSTHAN ='<',
SIGN_GREATERTHAN ='>',
SIGN_EQUALS ='=',
SIGN_DOUBLEEQUALS ='==',
SIGN_NOTEQUALS ='=!=',
SIGN_NOT ='!',
};
};
#endif /* TOKENTYPE_H_ */
当我尝试编译我的类令牌时,我收到一条错误消息
In file included from Token.h:10:0,
from Token.cpp:10:
TokenType.h:25:23: warning: multi-character character constant [-Wmultichar]
TokenType.h:26:21: warning: multi-character character constant [-Wmultichar]
Token.cpp: In constructor ‘Token::Token(int, int, TokenType, int)’:
Token.cpp:15:8: error: ‘class Token’ has no member named ‘TokenType’
Token.cpp: In member function ‘void Token::setValue(int*)’:
Token.cpp:20:19: error: invalid conversion from ‘int*’ to ‘int’ [-fpermissive]
Token.cpp: In member function ‘void Token::testPrint()’:
Token.cpp:24:89: error: expected primary-expression before ‘<<’ token
类 Token 没有名为 TokenType 的成员可能是这里的罪魁祸首。
Token.h 看起来像这样:
#ifndef TOKEN_H_
#define TOKEN_H_
#include "TokenType.h"
class Token {
int line;
int column;
TokenType tokenType;
int valueInt; //bei Integern muss Value gespeichert werden
int infoKey; //der Key aus der Symtableh
public:
Token(int line, int column, TokenType tokenType, int infoKey);
void setValue(int* value);
void testPrint();
virtual ~Token();
};
#endif /* TOKEN_H_ */
最后 token.cpp 看起来像这样:
#include <iostream>
using namespace std;
#include "Token.h"
Token:: Token(int line, int column, TokenType TType, int infoKey) {
this->line = line;
this->column = column;
this->TokenType = TType;
this->infoKey = infoKey;
}
void Token::setValue(int* value){
this->valueInt = value;
}
void Token::testPrint(){
cout << "Token: Line: " << line << " Column: " << column << " TokenType: " <<TokenType << " Infokey: " <<infoKey;
}
Token::~Token() {
// TODO Auto-generated destructor stub
}
为什么令牌找不到令牌类型?我只是 C++ 的初学者。请帮我。
提前致谢,
亲切的问候,凯文