Char dynamic array

Hello, I'm trying to adjust this program to make it run for customer size (s). i cant seem to figure out how to make the program accept the (s) value.

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
39
40
41
42
class PNODE_ : public BEST_NODE_
{
    public:
	int s = 4;
	PNODE_(const char *, int empty_x, int empty_y);
        PNODE_(const char *, int, int, int, int);
        int get_x() const;
        int get_y() const;
        const char (*get_board() const)[s];

// implementation of virtual functions
        int equal(const VOBJECT_ &) const;
        void display() const;
        NODE_ *do_operator(int) const;
    private:
        PNODE_
            *do_left() const,
            *do_right() const,
            *do_up() const,
            *do_down() const;
            int* compare_board(const char [s][s]) const;
        int
            x,
            y;
        char
            board= new char[s][s];
};



class PUZZLE_ : public BEST_
{
    public:
        PUZZLE_(PNODE_ *start, PNODE_ *target);
        int compute_g(const NODE_ &);
        int compute_h(const NODE_ &);
    private:
        int totdist(const char [s][s], const char[s][s]);
                       // computes manhatten distance
	PNODE_ *goal;  // goal node, needed by totdist()
};
A 2d array is not created like that. Instead:
1
2
3
4
5
char **board= new char*[s];
for(int i = 0; i < s; ++i)
{
  board[i] = new char[s];
}


It is passed to function like so:

int* compare_board(const char **) const;
A 2d array is not created like that. Instead:

Thank you for the reply. when i add the for loop it is causing a "error C2059: syntax error : 'for' " I'm assuming i should have added the loop else where?
Last edited on
You can do this within a function only. Keep in mind that it is essential to initialize variables within the constructor.
Topic archived. No new replies allowed.