View Single Post
Old 02-02-2003, 12:56 PM   #1 (permalink)
SuperFerrell
Registered User
 
SuperFerrell's Avatar
 
Join Date: Feb 2003
Location: an obscure fold of space-time
Posts: 2
SuperFerrell is on a distinguished road
Send a message via AIM to SuperFerrell
Operator= overloading

Hey, first post here, seems like a cool forums, hopefull I'll be a frequent poster.

I'm having some trouble with operator overloading here, it doesn't really like my operator=. Some background, I'm writing a simple language scanner/parser for an assembly language class (we have a virtual assembly language we're writing an interpreter for, this project is a pseudo-assembler to put the asm code into raw op codes for the interpreter)... so I'm using a token object (it's just a struct, might end up making a class out of it, not that it matters), and here's the code it doesn't like:

Code:
token& operator= (const token& right) {
	tokenID = right.tokenID;
	return this;
}
Borland's command line compiler (5.5.1) is giving me "Reference initialized with 'token * const', needs lvalue of type 'token' in function token:: operator =(const token &)" on the return line.

any help would be greatly appreciated

<EDIT> I got it to compile by changing the return to "return *this;" ... but it doesn't work properly, I'm still getting the initial value set by this's constructor </EDIT>
SuperFerrell is offline   Reply With Quote