B
bgordon0
Here's my class and its constructor:
class gBoard {
public:
gBoard();
private:
//cell[][] is like the 4th quadrant with Y first and always
positive
int cell[10][10]; //0 for empty, ship code for ship, -1 for hit
int hits[5]; //hits[shipnumber] is the number of times its been
hit
int setShips(int, int); //direction, ship#
void clearBoard();
void generateBoard();
string ships[5];
int shipSizes[5];
static char letters[10];
};
gBoard::gBoard() { //constructor
ships = {"destroyer", "submarine", "cruiser", "battleship",
"aircraft carrier"};
shipSizes = {2,3,3,4,5};
letters = {'A','B','C','D','E','F','G','H','I','J'};
clearBoard();
generateBoard();
}
I have those clearBoard() and generateBoard() functions below that
code, this is what they look like:
void gBoard::clearBoard() { ... }
void gBoard::generateBoard() { ... }
When I complile it tells me "xx.cpp:21: syntax error before `{' token".
This is the line of the ships array being filled with the name of the
ships. When I insert some dummy code above it, the line number in the
compiler error is still that array assignment line, so I know it's not
a problem with the line above. Also it tells me:
xx.cpp: At global scope:
xx.cpp:22: ISO C++ forbids declaration of `shipSizes' with no type
xx.cpp:22: initializer for scalar variable requires one element
xx.cpp:23: ISO C++ forbids declaration of `letters' with no type
xx.cpp:23: initializer for scalar variable requires one element
xx.cpp:24: ISO C++ forbids declaration of `clearBoard' with no type
xx.cpp:25: ISO C++ forbids declaration of `generateBoard' with no type
xx.cpp:26: syntax error before `}' token
These are already declared, and whats with the the error with }? That
line is the ending } on the constructor function. Could these weird
errors be related to the first one? What's interesting is that it
considers the body of the constructor as part of the main program.
Anyone know what's going on?
Thanks
class gBoard {
public:
gBoard();
private:
//cell[][] is like the 4th quadrant with Y first and always
positive
int cell[10][10]; //0 for empty, ship code for ship, -1 for hit
int hits[5]; //hits[shipnumber] is the number of times its been
hit
int setShips(int, int); //direction, ship#
void clearBoard();
void generateBoard();
string ships[5];
int shipSizes[5];
static char letters[10];
};
gBoard::gBoard() { //constructor
ships = {"destroyer", "submarine", "cruiser", "battleship",
"aircraft carrier"};
shipSizes = {2,3,3,4,5};
letters = {'A','B','C','D','E','F','G','H','I','J'};
clearBoard();
generateBoard();
}
I have those clearBoard() and generateBoard() functions below that
code, this is what they look like:
void gBoard::clearBoard() { ... }
void gBoard::generateBoard() { ... }
When I complile it tells me "xx.cpp:21: syntax error before `{' token".
This is the line of the ships array being filled with the name of the
ships. When I insert some dummy code above it, the line number in the
compiler error is still that array assignment line, so I know it's not
a problem with the line above. Also it tells me:
xx.cpp: At global scope:
xx.cpp:22: ISO C++ forbids declaration of `shipSizes' with no type
xx.cpp:22: initializer for scalar variable requires one element
xx.cpp:23: ISO C++ forbids declaration of `letters' with no type
xx.cpp:23: initializer for scalar variable requires one element
xx.cpp:24: ISO C++ forbids declaration of `clearBoard' with no type
xx.cpp:25: ISO C++ forbids declaration of `generateBoard' with no type
xx.cpp:26: syntax error before `}' token
These are already declared, and whats with the the error with }? That
line is the ending } on the constructor function. Could these weird
errors be related to the first one? What's interesting is that it
considers the body of the constructor as part of the main program.
Anyone know what's going on?
Thanks