次のような 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
class 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
}
token が tokentype を見つけられないのはなぜですか? 私はC ++の初心者です。私を助けてください。
前もって感謝します、
よろしく、 ケビン