this may be a very basic c++ question but I am a bit rusty. I am trying to set up a maze type data structure with points. Here is my code.
class Point{
public :
int xCoord;
int yCoord;
bool visited;
//constructors
Point(){}
Point(int x, int y){
xCoord = x;
yCoord = y;
visited = false;
}
int makeVisited(){
visited = true;
}
int makeUnvisited(){
visited = false;
}
};
class Maze{
public :
int width;
int height;
Point ** grid;
//constructors
Maze(){}
Maze(int X, int Y){
width = X;
height = Y;
grid = new Point*[width];
for(int i = 0; i < width; i++){
grid[i] = new Point[height];
for(int j = 0; j < height; j++){
grid[i][j] = new Point(i, j);
}
}
}
}; //end of Maze class
When I try to asign grid[i][j] a new point instance, I get an error saying
“error no operator “=” matches these operands”
Can someone tell me what I did wrong with the initialization of the point object?
Since
gridis declared as aPoint**, thengrid[i][j]is of typePoint. So you can’t assign anew Pointto this.One thing you can do is to define a setter member function, like:
And then in your loop you can use: