-
Need Class/Array help
I've been trying to write a simple program to make a tic tac toe game. I've gotten most of it done, but it won't accept my header file. Here's a sample of the code the compiler won't accept.
#ifndef _TICTACTOE_H
#define _TICTACTOE_H
class tic
{
public:
tic();
void MakeGrid();
void GetLocationPlOne(int);
void GetLocationPlTwo(int);
void CheckPlOneWin();
void CheckPlTwoWin();
private:
int index, dex, x;
char t[3][3];
};
tic::tic()
{
t[3][3]={
{ 49, 50, 51},
{ 52, 53, 54},
{ 55, 56, 57}
};
}
The compiler doesn't seem to like the **t[3][3]={ ** part. It gives me an error. Any help would be nice.
-
maybe the compiler doesn't like the underscore preceding the file name in the inclusion gaurd.
private:
int index, dex, x;
char t[3][3];
}; //this ends the class definition
therefore place a line called
#endif
here to complete the inclusion gaurd.
//place this constructor and other function definitions in a file
//called _tictactoe.cpp (or tictactoe.cpp if the underscore is not
//acceptable)
tic::tic()
{
t[3][3]={
{ 49, 50, 51},
{ 52, 53, 54},
{ 55, 56, 57}
}; //leave this semicolon off
} //drop this }
-
Ummm.... you don't quite understand. That was only a _sample_ of my code. The whole code goes on for another six pages.
t[3][3]={ ///////this is the error line
{ 49, 50, 51},
{ 52, 53, 54},
{ 55, 56, 57}
};
I'm not sure what's wrong with it. It won't let me initialize my array. Everything else works okay, though.
The compiler I'm using is Microsoft Visual C++ 5.0(or something close to it) if that helps any.
-
Try this:
Code:
t[3][3] = { 49, 50, 51, 52, 53, 54, 55, 56, 57 };
That should work.
-
tic::tic()
{
//whatever
};
is wrong. You don't put a semicolon after method definitions. Likewise, you don't need a second closing brace after the semicolon.
As for
t[3][3] = {//this is the error line.
truly being the error line. May well be. I would try one the following replacements if removing the semicolon and extra brace as above doesn't fix things:
t[][] = {
or
t = {
or the replacement code I feel most likely to work:
tic::tic()
{
int dummy = 49;
int i, j;
for(i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
{
t[i][j] = dummy++;
}//end inner for
}//end outer for
}//end tic()
Hopefully one of those changes will clear the error message.
Since t is a multidimensional char array each value of dummy will likely be converted to ASCII character set equivalent, although I don't know what the ASCII characters for integer values 49 through 57 are.
-
Thanks for the replies. I think I found the problem in my program.
And yes, I do know the numbers will be changed into ASCII, that's the point.
Thanks again!