我试图编译我的C++代码时遇到标题中提到的错误。我无法理解我在这里做错了什么。编译错误:' - >'的基本操作数具有非指针类型'令牌'
编译器在执行bool operator==(Token)
函数时遇到问题。我认为这是超载运营商的方式。
任何线索,为什么编译器不喜欢我指 this->terminal
或this->lexeme
?
class Token {
public:
tokenType terminal;
std::string lexeme;
Token *next;
Token();
bool operator==(Token &t);
private:
int lexemelength, line, column;
};
bool Token::operator==(Token &t) {
return ((this->terminal == t->terminal) &&
(this->lexeme == t->lexeme));
}
这不是''这个,因为它是't'。 – chris 2013-03-03 04:17:06
请注意,比较运算符的规范声明是'bool operator ==(const Token&t)const;'(其中我添加了两个额外的'const'指示)。 – 2013-03-03 04:57:17
@qream如果这回答你的问题,随时接受答案;) – Qix 2014-10-03 17:34:41