modifiable lvalue

so, i have the following code

1
2
3
4
5
int isEmptySquare[39][39]; /*as a global variable*/
void drawBoard(){
	if(!initialized){
		isEmptySquare[0]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	}/*this is inside a function*/


and i get the following errors, isEmptySquare: expected a modifiable lvalue.
Why? isnt the matrix modifiable?

thank you in advance
You can't assign arrays using the = operator except for initialisation. If you want to initialise your entire isEmptySquare to zero at the time of initialisation, then i'd suggest doing this instead:

int isEmptySquare[39][39] = { 0 };
This sets the entire array (not just one element) to zero.

If you need to reset it to zero later on, then you'll need to do it in some other way, such as std::fill()

Also, your comment suggests you've used a global variable. I'd strongly suggest you avoid using globals for all the trouble it will likely cause you later on when you have globally visible/modifiable data.
Last edited on
but thats just one of the lines of the matrix
some will be like isEmptySquare[4]={1, 0, 0, 0, 0, 2, 1, 1, 0, 1, 0, ......}

eventually i will change it, but for now its useful for it to be global
The fact remains that you cannot assign data to entire arrays using assignment, you can only do it at the time of initialisation. (or you can assign individual values one-at-a-time)

Will the data ever change? if its a lookup table you could dump the data into the whole thing at initialisation time. e.g.
1
2
3
4
5
6
7
8
int my_array[5][5]= 
{
    { 1,2,3,4,5 },
    { 2,3,4,5,6 },
    { 3,4,5,6,7 },
    { 4,5,6,7,8 },
    { 5,6,7,8,9 }
}; 


If your data is a bit more dynamic than that, perhaps you could read the data from a file.
Last edited on
its static, so i'll probably do that. I just tried the other way because a friend of mine managed to do it. He is using linux and gpp to compile and I'm using visual c++, could that make any difference?
and, another thing, now i tried to initialize de array, but now it was inside of a class, and it returned an error. How to initizalise t inside the class?
In the initializer list. That is, if you're using C++11, I'm not sure if it works in C++03, I remember having problems with that at some point though.
but, how?
constructor():matrix({0,0,1,0},{1,2,1,1}){} ?
Topic archived. No new replies allowed.