does anyone know what this means?

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2008
Posts: 23
Reputation: MJFiggs is an unknown quantity at this point 
Solved Threads: 0
MJFiggs's Avatar
MJFiggs MJFiggs is offline Offline
Newbie Poster

does anyone know what this means?

 
0
  #1
Nov 20th, 2008
I have had this problem a couple of times but i am unsure of what it means. could someone tell me what the error message "non-lvalue in assignment" translates to in english, please?
Now... FEAR THE BUNNY!!!
|\\ //
|(0.0)
|(> <)
||d b
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Re: does anyone know what this means?

 
1
  #2
Nov 20th, 2008
That means you are literally treating something that isn't an lValue as an lValue.

For example if a method doesn't return a reference to something, its possible that attempting to treat the method as an lvalue wont work since you're returning a copy of the actual object in which that copy may not be assigned to anything else...

It's actually hard for me to believe that you can't treat a temporary as an lValue considering potential chained = statements.

I believe this is an appropriate example--

( please excuse the code inlining - I'm in a hurry @_@ )
  1.  
  2. int method(){
  3. return 9;
  4. }
  5.  
  6. int& method2(int num){
  7. return num;
  8. }
  9.  
  10. int main(){
  11.  
  12. method() = 8; // should throw an error
  13. int x = 10;
  14. method2(x) = 5; // valid since the method returns a reference which can be assigned
  15. a value
  16.  
  17. }

Edit: Actually its possible that primitive types, which aren't objects, will be the most likely to flag such an error. It's possible that the assignment operator isn't valid for 'const' or temporary types (which makes sense, otherwise you could change the value of the number 9 by assigning it 5 and get the value of 5 instead of 9 wen you need 9... that would be a pain @_@ )

-Alex
Last edited by Alex Edwards; Nov 20th, 2008 at 7:21 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 23
Reputation: MJFiggs is an unknown quantity at this point 
Solved Threads: 0
MJFiggs's Avatar
MJFiggs MJFiggs is offline Offline
Newbie Poster

Re: does anyone know what this means?

 
0
  #3
Nov 20th, 2008
Ah, now I see what I was doing wrong. That makes sence. Thanks for your help.
Now... FEAR THE BUNNY!!!
|\\ //
|(0.0)
|(> <)
||d b
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC