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>
usingnamespace 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;
}
//
//Grid implemintation file
//
#include "Grid.h"
#include <iostream>
//#include <cassert>
#include <fstream>
usingnamespace 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;
returntrue;
}
returnfalse;
}
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;
returntrue;
}
returnfalse;
}
//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!
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.