Classes?

I have a Connect Four project, and I need to be able to access a part of another class within one class.

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
class Player pX
{
private:
	char player;

public:


int evalMove(int col, Board b)
{
//horizontal
	for (int row = 0; row < 6; row++)
	{
		for (int col = 0; col < 4; col++)
		{
			if (board[row][col] == player &&
				board[row][col+1] == player &&
				board[row][col+2] == player &&
				board[row][col+3] == player)
				return 100;

			if (board[row][col] == player &&
				board[row][col+1] == player &&
				board[row][col+2] == player)
				return 75;

			if (board[row][col] == player &&
				board[row][col+1] == player)
				return 50;

			if (board[row][col] == player)
				return 25;
		}
	}

//vertical
	for (int row = 0; row < 3; row++)
	{
		for (int col = 0; col < 7; col++)
		{
			if (board[row][col] == player &&
				board[row][col+1] == player &&
				board[row][col+2] == player &&
				board[row][col+3] == player)
				return 100;

			if (board[row][col] == player &&
				board[row][col+1] == player &&
				board[row][col+2] == player)
				return 75;

			if (board[row][col] == player &&
				board[row][col+1] == player)
				return 50;

			if (board[row][col] == player)
				return 25;
		}
	}


//upright diagonal
	for (int row = 5; row > 2; row--)
	{
		for (int col = 0; col < 4; col++)
		{
			if (board[row][col] == player &&
				board[row][col+1] == player &&
				board[row][col+2] == player &&
				board[row][col+3] == player)
				return 100;

			if (board[row][col] == player &&
				board[row][col+1] == player &&
				board[row][col+2] == player)
				return 75;

			if (board[row][col] == player &&
				board[row][col+1] == player)
				return 50;

			if (board[row][col] == player)
				return 25;
		}
	}


//down right diagonal
	for (int row = 5; row > 2; row--)
	{
		for (int col = 6; col > 2; col--)
		{
			if (board[row][col] == player &&
				board[row][col+1] == player &&
				board[row][col+2] == player &&
				board[row][col+3] == player)
				return 100;

			if (board[row][col] == player &&
				board[row][col+1] == player &&
				board[row][col+2] == player)
				return 75;

			if (board[row][col] == player &&
				board[row][col+1] == player)
				return 50;

			if (board[row][col] == player)
				return 25;
		}
	}


}

};


My problem here is that I keep getting the error that 'board' isn't defined, and I need to take 'board' from a different class and use it here. Board is identified here

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Board
{
private:
	char board [6][7];
public:
	Board();
	void getArray(char theArray[][7]);
	void printBoard();
	bool checkMove(int col);
	void makeMove(char player, int col);
	void undoMove(int col);
	bool isFull();
	void reset();
	bool hasWon(char player);
	void hostTournament();
};

Board::Board()
{
	// for every row and column pair fill in an 'e'
	for (int row = 0; row < 6; row++)
		for (int col = 0; col < 7; col++)
			board[row][col] = 'e';
}
You are passing a Board b but then you just attempt to access it like it is an array, and you are also calling it 'board'. Use your member functions in Board in order to get the array.
or overload the [] operator to make your player code valid
try to access board through something like b.board[row][col]. maybe your compiler doesn't know board is in b.

board is private, which may give you a new error. maybe you can use public method getArray to get a current copy of board?


by the way, what does pX do on line 1? i get errors when i do that.
Topic archived. No new replies allowed.