samedi 3 avril 2021

Dont know how to fix: expected primary-expression before '.' token

I'm currently just starting off coding in c++, the current project I'm working on is making an in-console chess engine type thing. The function below is supposed to check if a particular square has a piece on it, and if so, if the piece is white. Board.grid is a 2D array of strings where " " would be an empty square, "wR1" one of the white rooks, "bQ1" the black queen, etcetera. I got the error expected primary-expression before '.' token on both if statements inside the functions and think it's got to do with the .at() function called on the 'square string', but have no clue why this would give an error or what could be done to resolve it.

I would appreciate it greatly if anyone could help me with this. Thanks in advance!

bool getSquare (int square[2])
{
    bool isOccupied = false;
    bool isWhite = false;

    if (Board.grid[square[1]][square[0]].at(0) != " "){isOccupied = true;};
    if (Board.grid[square[1]][square[0]].at(0) == "w"){isWhite = true;};

    bool arr[2] = {isOccupied, isWhite};
    return arr;
};

Aucun commentaire:

Enregistrer un commentaire