ticTacToe.h
Kod: Zaznacz cały
#pragma once
class ticTacToe
{
public:
ticTacToe();
//constructor, it initialises the 3X3 board of *
void printBoard() const;
//function to print a board
void getAMove();
void moveValidation();
void determineWinner();
private:
static char board[3][3];
};
Kod: Zaznacz cały
#include "stdafx.h"
#include "ticTacToe.h"
#include <iostream>
using namespace std;
ticTacToe::ticTacToe()
{
int row, col;
for (row=0 ; row < 3 ; row++)
for (col=0 ; col < 3 ; col++)
board[row][col]='*';
}
void ticTacToe::printBoard() const
{
int row , col;
for (row=0 ; row < 3 ; row++)
{
cout<<endl;
for (col=0 ; col < 3 ; col++)
cout << board[row][col] << " ";
}
}
Kod: Zaznacz cały
#include "stdafx.h"
#include <iostream>
#include "ticTacToe.h"
using namespace std;
int main()
{
ticTacToe player1;
ticTacToe player2;
cout<< "Let's start the game \n";
player1.printBoard();
cout<<endl;
system("PAUSE");
return 0;
}
Zupełnie nie wiem dlaczego ale po usunięciu static'a wszystko jest ok1>ticTacToe.obj : error LNK2020: unresolved token (0A000321) "private: static char (* ticTacToe::board)[3]" (?board@ticTacToe@@0PAY02DA)
1>ticTacToe.obj : error LNK2001: unresolved external symbol "private: static char (* ticTacToe::board)[3]" (?board@ticTacToe@@0PAY02DA)