Dunno what to do from here

So i'm trying to test my class so i can start writing the driver and have faith that the it will all work but i am running into this incredibly frustrating error...

Error 1 error C2143: syntax error : missing ';' before 'using' c:\users\tyler\documents\visual studio 2010\projects\cs150_program_3\cs150_program_3\grid_driver.cpp 7 1 cs150_Program_3
Error 2 error C2143: syntax error : missing ';' before 'using' c:\users\tyler\documents\visual studio 2010\projects\cs150_program_3\cs150_program_3\grid.cpp 8 1 cs150_Program_3

Here is the code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//
//uses the grid and sortedlist classes to create crossnumber puzzles
//
#include "Grid.h"
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
	int i, j;
	Grid grid1;
	cout<<grid1.getHeight()<<grid1.getWidth();
	for (i=0;i<grid1.getHeight();i++)
		for(j=0;j<grid1.getWidth();j++)
			cout<<grid1.at(i,j);
return 0;

}


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
117
118
//
//Grid implemintation file
//
#include "Grid.h"
#include <iostream>
//#include <cassert>
#include <fstream>
using namespace std;

//constructor functions

Grid::Grid()
	//This is the default constructor for the class Grid
	//By default the grid is populated with spaces and 
	//width and height are set to their max values
{
	Width = MAX_WIDTH;
	Height = MAX_HEIGHT;
	int i, j;
	for(i=0;i<Height;i++)
		for(j=0;j<Width;j++)
			gridTypes[i][j]=DEFAULT_VALUE;
}

Grid::Grid(const Grid &firstGrid)
	//this is the copy constructor for the class grid
	//this constructor sets all values to match exactly with
	//the previous grid
{
	int i, j;
	setHeight(firstGrid.getHeight());
	setWidth(firstGrid.getWidth());
		for(i=0;i<Height;i++)
			for(j=0;j<Width;j++)
				gridTypes[i][j]=firstGrid.gridTypes[i][j];
}

//Mutator functions

bool Grid::setHeight(int NuHeight)
	//This function checks that the specified height of the grid
	//is less than or equal to the max value of height
	//if it is then the specified value will become 
	//the height of the grid otherwise it will return false
	//and make no change
{
	if (NuHeight >= MAX_HEIGHT)
	{
		Height = NuHeight;
		return true;
	}
	return false;
}

bool Grid::setWidth(int NuWidth)
	//This function checks that the specified width of the grid
	//is less than or equal to the max value of width
	//if it is then the specified value will become 
	//the width of the grid otherwise it will return false
	//and make no change
{
	if (NuWidth >= MAX_WIDTH)
	{
		Width = NuWidth;
		return true;
	}
	return false;
}

//accessor functions

int Grid::getHeight() const
	//Returns the current value of Height
{
	return Height;
}

int Grid::getWidth() const
	//returns the current value of Width
{
	return Width;
}

char& Grid::at(int row, int col)
	//if this function is passed inappropriate values for row and col
	//the program will be crashed
	//if the assert statement is passed this returns the address of the element at the specified position
{
	//assert((row>Height) && (col>Width))
	if(row>=Height && col>=Width )//i know assert should be used here but i keep getting an error that takes me into the assert.h file and i have no interest in messing with that
		exit(1);
	return gridTypes[row][col];
}

//overloaded function

void Grid::operator=(const Grid& G)
	//sets all data members for *this grid to be the same as 
{
	int i, j;
	Height=G.Height;
	Width=G.Width;
	for(i=0;i<Height;i++)
		for(j=0;j<Width;j++)
			gridTypes[i][j]=G.gridTypes[i][j];
}

//friend functions

//istream& operator >>(istream& sourceFile, Grid& G)
	//this friend function assumes that the format of the grid is 
	//set up in the file exactly how it is to be displayed
//{
	//int i, j;
	//for(i=0;i>G.Width;i++)
		//for(j=0;j<G.Height;j++)
			//sourceFile>>G.gridTypes[i][j];
//} 



i figure i must have messed up somewhere other than using namespace std; but i really have no idea what the error could be... please help!
It sounds like you might have forgotten the ; that should be at the end of your class definition (where ever that is.)
1
2
3
class Grid {
  ...
}; //<-- Did you remember this guy? 


If not, the error seems to be somewhere at the end of the file Grid.h that you are including in both of these files.

FYI: all files that don't have a main function should be *.h files...
The error is probably in your Grid.h file. Are you forgetting a semicolon after your class definition?

1
2
3
4
class Grid
{
  //...
};  // <- don't forget this 


If that's not the problem, please post Grid.h as well and maybe we can spot it.
There is an error i will never forget again :] thanks a lot!! and btw i know they should all be .h files but my teacher is weird....
From Mathhead200 -

FYI: all files that don't have a main function should be *.h files...


No.

Typically for a class, the class definition is put in a header file and the implementation is in a code file as you did above with Grid.h and Grid.cpp. One exception would be for templates which usually must all be in the header file.
Topic archived. No new replies allowed.