I just started messing around with classes and have been trying to figure out this error for an hour or so. Here is the compiler error:
g++ player.cpp tictactoe.cpp
TicTacToe.h:15: error: expected constructor, destructor, or type conversion before ';' token
player.cpp:26: error: 'TicTacToe' has not been declared
player.cpp: In member function 'void Player::NextMove(int)':
player.cpp:35: error: request for member 'setValue' in 'toe', which is of non-class type 'int'
Player.cpp
#include <iostream>
#include "TicTacToe.h"
using namespace std;
class Player
{
public:
Player(char *pname, int pnumber)
{
strcpy(name, pname);
number = pnumber;
}
int GetIndex() { return number; }
char * GetName() { return name; }
void NextMove(TicTacToe toe)
{
int row, col;
do
{
cout << "\nPlayer " << number << ": Enter the Row and Column for your next move: ";
cin >> row >> col;
}
while (toe.setValue(row, col, number) == false);
}
private:
char name[];
int number;
};
TicTacToe.cpp
#include <iostream>
using namespace std;
class TicTacToe
{
public:
void print(); //prints out the gameboard at any time
int getStatus(); //returns tie, win for either player, or neither
TicTacToe();
bool setValue(int row, int col, int player)
{
if(row < 4 && col < 4 && row > 0 & col > 0)
{
if(isEmpty(row, col) == true)
{
char a;
if(player == 1) a = 'x';
else a = 'o';
board[row-1][col-1] = a;
return true;
}
else
{
cout << "\nSpace already occupied. Try again.\n";
return false;
}
}
else
{
cout << "\nInvalid position. Try again.\n";
return false;
}
}
private:
bool isEmpty(int row, int col)
{
if (board[row-1][col-1] == '\0') return true;
else return false;
}
char board[3][3];
};
TicTacToe::TicTacToe()
{
int x, y;
for(x = 0; x < 3; x++)
{
for(y = 0; y < 3; y++)
{
board[x][y] = '\0';
}
}
}
TicTacToe.h
#include <iostream>
using namespace std;
TicTacToe();
void print();
int getStatus();
bool setValue(int, int, int);
This is a TicTacToe game(nowhere near finished, but shouldn't be too hard after I knock out my syntax errors)
Thanks for the help