c++ – Error: expression must have a pointer type when using the this keyword
c++ – 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.
I guess this->grid
is of type Square*
, so this->grid[0]
is of type Square&
and you must use .
(dot) not ->
(arrow) to access members from Square&
. To use arrow for expression expression must have a pointer type…
this->grid[i*col + j]->key2
// ^^: this->grid[i*col + j] is not a pointer
this->grid[i*col + j].key2
// ^ use dot to access key2 and key1 too