Original Post
Hi, I'm making a Tic-Tac-Toe game, but I'm having problems with the file includes. The compiler error stumps me, because it goes away if I put all the files into one big file. Here are my files:
Main.cpp
Game.h
Board.h
Board.cpp
Game.cpp
The error given is:
c:\mfc testing\tic tac toe\game.h(14) : error C2629: unexpected 'class CGame ('
c:\mfc testing\tic tac toe\game.h(14) : error C2238: unexpected token(s) preceding ';'
And some others. These are the main ones I cannot solve.
[edited by - UBC_Wiskatos on August 3, 2002 6:15:54 PM]
#include "Game.h"
#include "Board.h"
int main()
{
CBoard theBoard;
// CPlayer Player[2];
CGame theGame(&theBoard);
return 0;
}
#ifndef GAME_H
#define GAME_H
/**********************************************
Class: Game
Author: UBC_Wiskatos
Function: Controls the whole game (input, etc.)
**********************************************/
class CGame
{
public:
CGame();
CGame(CBoard *pBoard); // Main constructor
~CGame(); // Main destructor
private:
};
#endif
#ifndef BOARD_H
#define BOARD_H
class CBoard
{
public:
CBoard(); // Main constructor
~CBoard(); // Main destructor
void Draw(); // Draws the board
private:
int m_board[3][3];
int m_rows;
int m_cols;
};
#endif
#include "Board.h"
#include <iostream>
using namespace std;
CBoard::CBoard()
{
// Set the number of rows and columns
m_rows = 3;
m_cols = 3;
// Clear the screen
system("cls");
// Set the array cells to 0
for(int y = 0; y < m_rows; y++)
{
for(int x = 0; x < m_cols; x++)
{
m_board[x][y] = 0;
}
}
// Draw a blank board
Draw();
m_board[1][1] = 2;
}
CBoard::~CBoard()
{
}
void CBoard::Draw()
{
// Clear the screen
system("cls");
// Display our heading
cout << "TIC-TAC-TOE" << endl << endl;
// Loop through the rows
for(int y = 0; y < m_rows; y++)
{
// Loop through the columns
for(int x = 0; x < m_cols; x++)
{
// Add a blank space in front of character
cout << " ";
// If we find a 1, put an X, if we find a 2,
// put an O, if neither, put a space
switch(m_board[x][y])
{
case 1:
cout << "X";
break;
case 2:
cout << "0";
break;
default:
cout << " ";
}
// Add a blank space after character
cout << " ";
// If we are not on the last column, put a #
if(x < m_cols - 1)
{
cout << "#";
}
}
// Finish up the line
cout << endl;
// If we are not on the last row, put the line
if(y < m_rows - 1)
{
// Loop through the number of columns
for(int i = 0; i < m_cols; i++)
{
// For each column, put ###
cout << "###";
// If we are not on the last column, add an extra #
// for the dividers that split columns
if(i < m_cols - 1)
{
cout << "#";
}
}
// Finish up the line
cout << endl;
}
}
}
#include "Game.h"
CGame::CGame()
{
}
CGame::CGame(CBoard *pBoard)
{
pBoard->Draw();
}
CGame::~CGame()
{
}