left operand must be l-value

I get this error from the following code:

Class obj1[3];
Class obj2[3];
obj2 = obj1;

why do I get this error? isn't obj2 supposed to be a pointer?
I mean I can do *(obj2+1) right? so why doesn't it let me make the object pointed to by obj2 the same as the object pointed to by obj1?

Thank you!

Santiago
Last edited on
why do I get this error? isn't obj2 supposed to be a pointer?

No, it's an array. Use fixed C++ arrays (std::array) or dynamic arrays (std::vector) if you want to be able to assign them to each other.

I mean I can do *(obj2+1) right?

That's because obj2 can be implicitly converted to a pointer to its first element.
Thanks Athar!

One more thing, what does "left operand must be l-value" mean? what's an l-value?

Santiago
An lvalue is a value that may appear on the left side of an assignment.
That's a bit of a misleading message on the compiler's side. obj2 is, in fact, an lvalue expression. It just isn't assignable.

Other compilers say:
gcc 3.4.6: error: ISO C++ forbids assignment of arrays
gcc 4.6.2: error: invalid array assignment
clang++: error: array type 'Class [3]' is not assignable
intel: error: expression must be a modifiable lvalue
sun: Error: The operand "*obj2" cannot be assigned to.
Topic archived. No new replies allowed.