“Error: expression must have a pointer type” when using the “this” keyword

You have to use

this->grid[i*col + j].key1
this->grid[i*col + j].key2

That is because even if it is true that your grid is a pointer, you have allocated in the are pointed by its memory an array of Square object. So when you use the [] operator you are obtaining an object of type Square and not a Square* and for a Square object you hve to use the . operator and not the -> operator.

Leave a Comment