Maze

Hello guys!I have a problem with my code(maze solver) so i need your help.
I have to solve a maze(2d grid) with dfs.I m not going to release the whole program but the part that i have problem.
Well i have a class State where i keep positions of robot , the grid , an array of strings with direction and the size of the path.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 class State
{
    int robX,robY;
    bool free[WIDTH][HEIGHT];
    int pathSize=0 ;
    string *path=NULL;

public:
   State(){ }

   State(int x,int y)
    {
        robX = x;
        robY = y;
        for(int i=0;i<WIDTH;i++){
            for(int j=0;j<WIDTH;j++){
                free[i][j] = true;
            }
        }

    }

    State(const State &old)
    {

        this->robX = old.robX;
        this->robY = old.robY;
        for(int i=0;i<WIDTH;i++){
            for(int j=0;j<WIDTH;j++){
                this->free[i][j] = old.free;
            }
        }
        this->pathSize = old.pathSize;
        this->path = old.path;


    }
   ....


The problem is that i can not copy the old path to the current so when i runn
the program the pathSize is 0.
what is the string 'path' supposed to be holding?
"can not copy." Why?

What does the pathSize represent?


Regardless,

* Line 9 doesn't initialize robX, robY, free.

* Line 16 has an error. How many elements per row? Repeats on line 29.

* Line 30. Assignment of bool[][] into bool.

* Wouldn't default copy constructor suffice?
mutexe : string path hold the direction that follow the robot ( 'LEFT','RIGHT'...etc)

keskiverto : The pathSize is the size of the array path.

* i have code in State but i didn't copy it here..

* WIDTH = HEIGTH

* here i paste it wrong.In my code i have
this->free[i][j] = old.free[i][j];

* Ok i new to c++ so in this part i need your help.
The default constructor is this?
State(const State &old);
In this case the program compile with error undefined reference to `State::State(State conts& )'

I have try this constructor but i think is the same with the old one
1
2
 State(const State &old): robX(old.robX),robY(old.robY),
    pathSize(old.pathSize),path(old.path){}


The program run but the pathSize is 0.I m sure that the dfs and the other classes are
correct so i want to make sure that the copy constructor really copy the old fields to current.
Topic archived. No new replies allowed.