Connect Four Game board problem header file

How do I use the appropriate header file for this game?

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
43
44
45
46
/*


*/
//board.h-calculates and displays the cost of laying sod 

#include <iostream>

using std::cout;
using std::endl;
using std::cin;

//declaration section
class ConnectFour
{
public:
	ConnectFour();
	void board(char);
private:
	char place;
};

//implementation section
ConnectFour::ConnectFour()
{
	place[6][7];
}	//end of default constructor

void board(char p)
{
	place = p;
	cout<<" 1   2   3   4   5   6   7\n";
    for(int a = 0; a<= 5; a++)
    {
    for(int b =0; b <= 6; b++) cout<<char(218)<<char(196)<<char(191)<<" ";
    cout<<'\n';
    for(int b =0; b <= 6; b++) cout<<char(179)<<p[a][b]<<char(179)<<" ";
    cout<<'\n';
    for(int b =0; b <= 6; b++) cout<<char(192)<<char(196)<<char(217)<<" ";
    cout<<'\n';

    }

}	//end of SetDimensions method



I get these errors.
error C2109: subscript requires array or pointer type
error C2065: 'place' : undeclared identifier
error C2109: subscript requires array or pointer type


Line 20 should define the type and size. Currently you define the type (char) and the size (1).

Then in line 26 you suddenly refer to place[6][7] but place only represents 1 char.

Solution1:
Replace line 20:char place; with char place[6][7]; and delete line 26.

Solution2:
Replace line 20:char place; with char** place; and replace line 26:
1
2
place = new char*[6];
for (int i = 0; i < 6; ++i) place[i] = new char[7];

Last edited on
Topic archived. No new replies allowed.