Compilation error: base operand '-> has non-pointer type' Token

I get the error mentioned in the header when trying to compile my C ++ code. I am having trouble understanding what I did wrong.

The compiler has a problem with my implementation of the bool operator==(Token ) function. I thought this was a way to overload the operator.

Any hints as to why I don't like the compiler by 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)); } 
+6
source share
1 answer

Look carefully at your types. t is reference ( Token &t ), which means it should be used with the dot operator ( . ).

References are not pointers; think of them as already dereferenced pointers without pushing the actual object onto the stack (passing "by reference").

+11
source

All Articles