Hello, I am trying to declare a 2D array (3x3) inside of a class.
I have it set up like this:
GameBoard.cpp
#include "GameBoard.h"
#include <iostream>
using namespace std;
char board [3][3];
GameBoard::GameBoard()
{
board [0][0] = 'a';
board [0][1] = 'b';
board [0][2] = 'c';
board [1][0] = 'd';
board [1][1] = 'e';
board [1][2] = 'f';
board [2][0] = 'g';
board [2][1] = 'h';
board [2][2] = 'i';
}
Game.cpp (Driver)
#include "GameBoard.h"
#include <iostream>
using namespace std;
int main()
{
cout << "Let's play Tic-Tac-Toe!!" << endl <<
"Player 1 gamepiece is X" << endl <<
"Player 2 gamepiece is O" << endl <<
endl << "Here's how the board is laid out" << endl << endl <<
"a|b|c" << endl << "-----" << endl <<
"d|e|f" << endl << "-----" << endl <<
"g|h|i" << endl << endl <<
"Let's begin..." << endl;
//cout << GameBoard.board[0][0]; // illegal
//cout << GameBoard::GameBoard.board[0][0]; //illegal
return 0;
}
GameBoard.h
#ifndef GAME_H
#define GAME_H
#include <iostream>
using namespace std;
class GameBoard
{
private:
char a,b,c,d,e,f,g,h,i;
public:
GameBoard(); // default constructor to set gameboard to all blanks.
/*playerChoice(char, char); // player's choice (X or O, location on brd)
int isWin(); // displays a winner message
printBoard(ostream &); // displays the current board to screen*/
};
#endif
What I am trying to do right now is be able to display my array using the class. I tried some of those but they were illegal declarations.