我不确定我做错了什么。当我在一个文件中编译带有实现的头时,它工作,但是当我将它拆分为头文件和实现文件时,它无法识别实现文件中的数组。任何指导将不胜感激。或者是上一个问题的链接,我找不到。
HEADER FILE:
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <cstdio>
// declaration of the header
class TicTacToe
{
extern const int ArrSize = 3;
//function prototype
public:
TicTacToe(); //constructor
void makeBoard();
void printBoard();
void isValidMove();
void isWinner();
void getMove();
//data member
private:
int pRow, pCol, player;
bool validMove, winner;
char TTTarray[ArrSize][ArrSize];
};
实施文件(.cpp)
c++
#include <iostream>
#include "TicTacToe.h"
using namespace std;
const int arrSize;
//implementation section
TicTacToe::TicTacToe(){} // constructor
void TicTacToe::makeBoard()
{
int i, j;
for (i=0; i<3; i++){ // for row loop
for (j=0; j<3; j++){
TTTarray[i][j]='E';}}
pRow = 0;
pCol = 0;
player = 0;
validMove = false;
winner = false;
}
void TicTacToe::printBoard()
{
int i;
for (i=0; i<3; i++)
{
cout << TTTarray[i][0] << " " << TTTarray[i][1] << " " << TTTarray[i][2]
<< endl;
}
}
void TicTacToe::isValidMove()
{
char location;
location = TTTarray[pRow][pCol];
if(location == 'E')
validMove = true;
else
validMove = false;
}
&#13;