Thread: Error help '=fpermissive'

  1. #1
    Registered User
    Join Date
    Oct 2019
    Posts
    5

    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][0][z] == 8)&&(boardTwo[x][1][z] == 8)&&(boardTwo[x][2][z] == 8))||
               ((boardTwo[x][0][z] == 9)&&(boardTwo[x][1][z] == 9)&&(boardTwo[x][2][z] == 9)))
               {
                   if((boardTwo[x][0][z] == 8)&&(boardTwo[x][1][z] == 8)&&(boardTwo[x][2][z] ==8))
                   {
                       userScore++;
                   }
                   else
                   {
                       compScore++;
                   }
               }
            }
        }
        
        for(int y = 0; y < 3; y++)
        {
            if(((boardTwo[0][y][z] == 8)&&(boardTwo[1][y][z] == 8)&&(boardTwo[2][y][z] == 8))||((boardTwo[0][y][z] == 9)&&(boardTwo[1][y][z] == 9)&&(boardTwo[2][y][z] == 9)))
               {
                   if((boardTwo[0][y][z] == 8&&(boardTwo[1][y][z] == 8)&&(boardTwo[2][y][z] == 8)))
                   {
                       userScore++;
                   }
                   else
                   {
                       compScore++;
                   }
               }
        }

  2. #2
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,458
    In your second main loop (line 22), you use z (e.g. boardTwo[0][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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. -fpermissive case lable errors in switch -
    By userxbw in forum C++ Programming
    Replies: 2
    Last Post: 09-04-2017, 03:04 AM
  2. fpermissive compilation error using inheritance
    By ubmattpangolin in forum C++ Programming
    Replies: 5
    Last Post: 10-18-2015, 12:39 PM
  3. invalid conversion from 'int*' to 'int' [-fpermissive]
    By telmo_d in forum C Programming
    Replies: 2
    Last Post: 06-02-2015, 08:47 AM
  4. Compile error? Logic error? Syntax Error? Please help
    By Khody Afkhami in forum C Programming
    Replies: 4
    Last Post: 10-11-2014, 01:36 AM
  5. Replies: 5
    Last Post: 08-31-2013, 07:59 PM

Tags for this Thread