• Advertisement

Archived

This topic is now archived and is closed to further replies.

left operand must be l-value?

This topic is 5586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I get this compile error: left operand must be l-value when i run this code: objDesc.wszFileName = wszPath; Both var''s are WCHAR''s. What´s l-value and what´s wrong?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Is objDesc the name of the object or its class?

If its the name of the class it would be like trying to assign a type a value:

_ int = 100;
_ float = 100.53; // etc...

You just can''t do that.

Share this post


Link to post
Share on other sites
quote:
Original post by peter86
What´s l-value


The terminology is something of a carry over from the earliest days of C. The "L" stands for "left" as in left operand and there is also a corresponding "R" value - as in "right"

left = right

A "L-value" is a value into which another value can be assigned. For example a variable of some kind. As in the AP''s example

int = 0 - this won''t work because there''s no variable there to store the value - there''s only a type, but no space - there''s no there there.

int x = 0 - this works just fine because there''s a there there to store the value in

An "R" value is a value that can be stored in an "L" value - pretty much what is typically thought of as a ''value'' - a literal or a result returned by a function.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Could be a problem with it being private too.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
Could be a problem with it being private too.



I looked it up and it isn´t.

Share this post


Link to post
Share on other sites
if you created a class called objDesc with this member: wszFileName thats just fine.

But you have to create an object from that class to assign data too.

objDesc MyObject;

// this is legal
_ MyObject.wszFileName = whatever; // Only if member is a pointer and not an array

// Sorry no variable to assign data to no L-value
_ objDesc.wszFileName = whatever;

** remember you can't use a class name as an object **



[edited by - CodeJunkie on October 5, 2002 4:47:47 AM]

Share this post


Link to post
Share on other sites
Ignore the insane comment above.

You can''t assign anything to a C array, period.

  
int main ()
{
int array[10];
array = anyTypeInTheWorldYouCanThinkOf; // error

}

Arrays are not legal lvalues. Jan''s answer was correct.

HTTP 500 retry #1..

Share this post


Link to post
Share on other sites
Have you been talking to my doctor?!
He has called me crazy but never insane.

Yes this would be a very bad idea!!!
. array = anyTypeInTheWorldYouCanThinkOf; // error

You can''t assign anything to a C array, period. Huh????

I always thought you could assign an address to a pointer. (like using new perhaps)

I used ''whatever'' as a generic variable/r-value name only and was not trying to indicate that you could/should assign any value you liked into a pointer. So, I''m sorry for the confusion.

And, yes you''re right to copy data from one array to another. Because, having two or more different pointers that can manipulate the same data at the same time could cause confusion which may introduce hard to track bugs.

However, I do like to pass some arguements by reference instead of by value. (like bitmaps, strings, etc...) So I''ll continue to assign addresses to pointers to pass large data in a method. Well, until the C++ standard considers that to dangerous and bans that from the language.

Besides, I was trying to point out that you can not use a class definition in your program as an object because it''s not an object. I see it more like a structure definition with methods.

Again, Sorry for the insane confusion!!!

NO, I''m not insane! (Crazy...Damn It)

Share this post


Link to post
Share on other sites
Ok, yeah an array is not an l-value. Sorry, (all that talk of pointers was a little useless in this case) I got a little pointer insane.

P.S. I wonder how many others have confused arrays with pointers??




[edited by - CodeJunkie on October 5, 2002 4:39:54 AM]

Share this post


Link to post
Share on other sites
Why not make them pointers instead of arrays?

And seeing that you''ve created a class.... Why not overload your = operator to support assigning those values to each other?

Just a thought.


Share this post


Link to post
Share on other sites
its a string. use string then.. :D

else strncpy is what you need to assign the data..

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites

  • Advertisement