943,694 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 442
  • C++ RSS
Nov 20th, 2008
0

does anyone know what this means?

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
MJFiggs is offline Offline
26 posts
since May 2008
Nov 20th, 2008
1

Re: does anyone know what this means?

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 @_@ )
c++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 392
Solved Threads: 108
Posting Shark
Alex Edwards is offline Offline
971 posts
since Jun 2008
Nov 20th, 2008
0

Re: does anyone know what this means?

Ah, now I see what I was doing wrong. That makes sence. Thanks for your help.
Reputation Points: 10
Solved Threads: 0
Light Poster
MJFiggs is offline Offline
26 posts
since May 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC