Search code examples
c++arrayscomma-operator

Array not assignable


I wanted to assign a boolean value to a two-dimensional boolean array, but the compiler showed an error

bool Amass[100][80];

Amass[1,1] = true; //even so I see only an error    

Solution

  • You have declared a two-dimensional array

    bool Amass[100][80];
    

    However in this statement

    Amass[1,1] = true;
    

    in the subscript operator expression you are using the comma operator. Its result is the right-most operand. That is the statement is equivalent to

    Amass[1] = true;
    

    So in the left side of the assignment there is used a one-dimensional array.

    It seems you mean

    Amass[1][1] = true;