Hi all,
I'm having a lot of difficulty trying to get this program to compile. I'm pretty new to C++, but what I've come up with so far makes logical sense to me, and I don't understand what the message "Request for member 'displayBoard' in 'game', which is of non-class type 'TicTacToe ()(char, char)' " means.
Here's the code:
#include <iostream>
#include <cstring>
using namespace std;
class TicTacToe
{
public:
TicTacToe(char player, char board[]);
void displayBoard();
int getMove();
private:
char board[9];
char player;
char box;
char X, O;
};
int main() // tests TicTacToe class
{
cout << "Let's play a game of Tic Tac Toe!";
int turns = 9;
TicTacToe game(char X, char E); // creates game object with player X, char Array E
while (turns > 0)
{
game->displayBoard();
game.getMove();
turns--; // decrements turn count
}
cout << "Game Over!";
return 0;
}
void TicTacToe::displayBoard() //displays board
{
cout
<< board[0] << " | " << board[1] << " | " << board[2] << "\n"
<< board[3] << " | " << board[4] << " | " << board[5] << "\n"
<< board[6] << " | " << board[7] << " | " << board[8] << "\n";
}
int TicTacToe::getMove() // gets move and fills in grid
{
cout << "Player " << player << ", please pick a number corresponding to the grid of available choices: \n";
cin.get(box);
if (isdigit(box))
{
if ((board[box] != X ) && (board[box] != O))
{
board[box] = player; // box is claimed by current player
if (player == X) // if statement changes players
player = O;
else player = X;
}
else
cout << "This box is already taken, please choose another: ";
}
else
cout << "This is not a number! Please choose an available number from 1-9: ";
return board[box];
}
I'm pretty sure this program is a little ways from being polished and complete, with loops not working as expected and whatnot, but without being able to compile it, I'm unable to see what changes I need to make to complete it. Some help would be much appreciated! Thanks!