我試圖編譯我的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