当我试图编译我的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));
}发布于 2013-03-03 12:19:34
仔细看看你的类型。t是一个reference (Token &t),这意味着必须使用点运算符(.)来引用它。
引用不是指针;可以将它们视为已经解除引用的指针,而无需将实际对象放到堆栈上(“按引用传递”)。
https://stackoverflow.com/questions/15182397
复制相似问题