I am trying to represent the Maze object which is a rectangular grid of cells i.e., a 2-dimensional array of Cell objects. But i am confused why i cant set it this way
m[1][1].setDown(false);
i will get the error "arr is a private member", but i am here using a settermethod on the cell object, so shouldnt it work? Is there another better way to represent the Cell object inside the maze?
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include<fstream>
#include<string>
#include <stack>
using namespace std;
class cell
{
private:
bool visited;
bool up, down, right, left;
int x, y;
int px, py;
char status;
public:
cell() {
up = down = right = left = 0;
x = y = 0;
status = ' ';
}
bool getUp() { return up; }
bool getDown() { return down; }
bool getRight() { return right; }
bool getLeft() { return left; }
bool getvisited() { return visited; }
void setUp(bool b) { up = b; }
void setDown(bool b) { down = b; }
void setRight(bool b) { right = b; }
void setLeft(bool b) { left = b; }
void setvisited(bool b=0) { visited = b; }
void setstatus(char s = ' ') { status = s; }
char getStatus() { return status; }
};
class Maze
{
private:
int row, col;
cell **arr;
public:
Maze(int r = 0, int c = 0)
{
this->row = r; this->col = c;
arr = new cell*[row];
for (int i = 0; i < row; i++)
arr[i] = new cell[col];
}
};
int main()
{
Maze m(5, 5);
m.arr[1][1].setLeft(true);
}