Reputation: 71
I get the error mentioned in the title when trying to compile my c++ code. I'm having trouble understanding what I did wrong here.
The compiler has a problem with my implementation of the bool operator==(Token )
function. I thought this was the way to overload an operator.
Any clues as to why the compiler doesn't like me referring to
this->terminal
or 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));
}
Upvotes: 7
Views: 18224
Reputation: 15103
Take a close look at your types. t
is a reference (Token &t
) meaning it must be referred to using the dot operator (.
).
References are not pointers; think of them as already dereferenced pointers without putting the actual object on the stack (passing "by reference").
Upvotes: 12