1. ## Error help '=fpermissive'

I am writing a 3D tic tac toe program and have run into several errors. The first is:
[Error] name lookup of 'z' changed for ISO 'for' scoping [-fpermissive]
[Note] (if you use '-fpermissive' G++ will accept your code)

I have no idea what -fpermissive or G++ is or how to fix it.
Here is the code that pertains to that error:
Code:
```int tdBoard::checkWinner()
{
for(int z = 0; z < 3; z++)
{
for(int x = 0; x< 3; x++)
{
if(((boardTwo[x][z] == 8)&&(boardTwo[x][z] == 8)&&(boardTwo[x][z] == 8))||
((boardTwo[x][z] == 9)&&(boardTwo[x][z] == 9)&&(boardTwo[x][z] == 9)))
{
if((boardTwo[x][z] == 8)&&(boardTwo[x][z] == 8)&&(boardTwo[x][z] ==8))
{
userScore++;
}
else
{
compScore++;
}
}
}
}

for(int y = 0; y < 3; y++)
{
if(((boardTwo[y][z] == 8)&&(boardTwo[y][z] == 8)&&(boardTwo[y][z] == 8))||((boardTwo[y][z] == 9)&&(boardTwo[y][z] == 9)&&(boardTwo[y][z] == 9)))
{
if((boardTwo[y][z] == 8&&(boardTwo[y][z] == 8)&&(boardTwo[y][z] == 8)))
{
userScore++;
}
else
{
compScore++;
}
}
}```  Reply With Quote

2. In your second main loop (line 22), you use z (e.g. boardTwo[y][z]), but the scope of z when declared as part of the for loop itself, like you've done, is the loop; i.e. 'z' does not (or should not) exist outside of the first main loop (z's lifetime is for the lifetime of the loop only). You could fix the scoping error by doing something like:

Code:
```int z;
for(z = 0; z < 3; z++){```
So that it still "exists" for your second main loop (line 22). But I wonder if the second main loop is correctly placed anyway. By the time line 22 is reached, assuming you fix the z lifetime/scope issue, z will be 4 and you'll end up with an out of bounds array access. The placement of that second main loop (for (int y = 0...) seems suspicious to me but I admit that I haven't analysed the code to actually see what you're attempting to do.  Reply With Quote

Popular pages Recent additions 8&&boardtwo[x][z], errors, forint, fpermissive, ifboardtwo[x][z] 