Header file Connect Four Game Problem
May 15, 2012 at 3:46pm UTC
I get the following errors when I try to compile this code for a connect four game, so far I only have the board made.
error C2109: subscript requires array or pointer type
error C2065: 'place' : undeclared identifier
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
* Arooj Mohammed C++ boardClass
*/
//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[6][7];
};
//implementation section
ConnectFour::ConnectFour()
{
} //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
May 15, 2012 at 3:50pm UTC
Change the type of the board function parameter to that of ConnectFour::place.
Also put ConnectFour:: before the function name on line 29.
Last edited on May 15, 2012 at 3:51pm UTC
May 15, 2012 at 4:22pm UTC
Thanks, but now i get this error:
error C2440: '=' : cannot convert from 'char' to 'char [6][7]' line 31
error C2109: subscript requires array or pointer type line 37
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
/* Arooj Mohammed C++ boardClass
*/
//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[6][7];
};
//implementation section
ConnectFour::ConnectFour()
{
} //end of default constructor
void ConnectFour::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
Would I put anything inside the constructor, and how do I fix error C2109?
May 15, 2012 at 5:48pm UTC
The error is that on line 31 you have place, which is a two-dimensional array of characters, while you are trying to assign to it "p" which is just a single character. That doesn't make any sense.
May 15, 2012 at 6:20pm UTC
std::memcpy(place, p, sizeof (place));
Topic archived. No new replies allowed.