error: invalid array assignment

This error is exactly what you may already be thinking, you cannot assign one array to another under the C++ standard. Or more specifically you cannot copy the values from one array to another using the assignment operator '='. Good news, there are plenty of alternatives to this limitation, there is a link at the bottom of this article explaining some of the most popular. 

The reason this feature cannot be supported is due to the fact an array name is an l-value object which cannot be written, and if the compiler implicitly converts the array to a pointer, the array information is gone and the data lengths are unknown. Which is similar behavior to what happens when passing an array to a function accepting a pointer. This is because the pointer is addressing the first element, not the array itself. Even though they are the same address, there are very different semantics that apply.

To see how you can achieve the equivalent of the failed assignment, read this faq for a few different options: How to copy an array.

Tags: array, assignment, error, invalid
Last update:
2014-07-19 06:30
Christopher Andrews
Average rating: 1 (4 Votes)

You can comment this FAQ

Chuck Norris has counted to infinity. Twice.