I'm designing a game "Battleship" and I can't get get rid of a syntax error in the header file. I'm using a 2-D array for my grid.

The error is:
error C2059: syntax error : '{'

The error seems really simple, but for some reason i can't get rid of the syntax error.

Thanks for the help.


#include <iostream>
using std::string;

const int ROW = 13;		//row
const char COLUMN = 13;	//column;

class BattleGrid
	//battleGrid constructor
	BattleGrid(string = "" , int = 0 , char = 0);
	//battleGrid destructor

	//string color[];				//sets the color
	//string draw();				//draws the battlegrids

	string guess;				//players guess
	int xCoordinate;				// letters
	char yCoordinate;				// numbers
	//int backGround;				//background

	int x[ROW] = {1,2,3,4,5,6,7,8,9,10,11,12,13};		//array x        error C2059
	char y[COLUMN] = {'a','b','c','d','e','f','g','h','i','j','k','l','m'};		//array y        error C2059
        // 2-D grid     error C2059
	int grid[ROW][COLUMN] = { {0,0,0,0,0,0,0,0,0,0,0,0,0},	
							  {0,0,0,0,0,0,0,0,0,0,0,0,0} }; 

The compiler doesn't like the fact that you are initializing this array between lines 10 and 47. It wants you to do the initialization after line 47. Is this a static array? If not, you may want to initialize it in the constructor. Anyway, check out this link. I don't think the const versus non-const is much of an issue. I think it is a matter of static versus non-static and WHERE you put the initialization. It wants you to do it OUTSIDE of the class definition, which ends at line 47.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.