Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
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
Old 02-04-2003, 03:14 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,711
redhead is on a distinguished road
Could it be:
Code:
token& token::operator=(const token& right)
{
  tokenID = right.tokenID;
  return *this;
}
instead??
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 02-04-2003, 09:44 AM   #3 (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
yes, I tried that, and it worked, but I'd rather use a reference to the object instead of a pointer to the object when assigning... with the pointer, I'm stuck using:
Code:
token x;
const int EOF_TOK = 7;
//....
token* y = x;
token* z = EOF_TOK;
I just decided to scrap the operator= and just have to use y.tokenID = x.tokenID or y.tokenID = EOF_TOK; ... while it isn't fancy and cool, it works, just extra typing in MANY lines of code
SuperFerrell is offline   Reply With Quote
Old 02-04-2003, 02:43 PM   #4 (permalink)
anon
Guest
 
Posts: n/a
with vi named buffers forget the typing and just use "Xp
  Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
operate overloading member function in C# sureshkumar_kc MS Technologies ( ASP, VB, C#, .NET ) 2 10-15-2004 02:36 AM
Reviewing Overloading.... MadMAxJr Standard C, C++ 1 02-28-2004 01:58 PM
c++ overloading sde Standard C, C++ 0 06-20-2002 07:38 PM


All times are GMT -8. The time now is 08:30 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting