【发布时间】:2016-11-24 19:16:58
【问题描述】:
我对函数“JOUER”有一点问题。 这几天我正在研究它,但我看不到问题。 主要问题是:[Error] 'int' 之前的预期主表达式和 [Error] 'char' 之前的预期主表达式。 代码如下:
#include <iostream>
using namespace std;
enum etat { victoire, continuer, null };
int qntMouv = 0;
class TicTacToe {
public:
TicTacToe();
etat etatJeux ();
void affichTab() const ;
bool getXOMouv (char symbolMouv);
bool mouvValid (int x, int y) const;
void recommence ();
void game();
void jouer();
private:
char tableau[3][3];
}; // fin classe TicTacToe
TicTacToe::TicTacToe()
{
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
tableau[i][j] = ' ';
qntMouv = 0; // le tableau est vide
} // fin constructeur TicTacToe
bool TicTacToe::mouvValid (int x, int y) const{
int lig, col;
if ( lig >= 0 && lig <= 2 && col >=0 && col <= 2 && tableau[x] [y] == ' ' )
return true;
else return false;
} // fin du bool mouvValid
etat TicTacToe::etatJeux () {
if ((tableau[0][0]) && (tableau[1][0]) && (tableau[2][0])) return victoire; //colomne
else if ((tableau[0][1]) && (tableau[1][1]) && (tableau[2][1])) return victoire; //colomne
else if ((tableau[0][2]) && (tableau[1][2]) && (tableau[2][2])) return victoire; // colomne
else if((tableau[0][0] ) && (tableau[0][1] ) && (tableau[0][2]))return victoire; // lignme
else if ((tableau[1][0]) && (tableau[1][1]) && (tableau[1][2])) return victoire; // ligne
else if ((tableau[2][0]) && (tableau[2][1]) && (tableau[2][2])) return victoire; // ligne
else if ((tableau[0][0]) && (tableau[1][1]) && (tableau[2][2])) return victoire; // diago
else if ((tableau[0][2]) && (tableau[1][1]) && (tableau[2][0])) return victoire; // // diago
else if (qntMouv < 9) return continuer;
return null;
} // fin etatJeux
void TicTacToe::recommence () {
qntMouv = 0;
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
tableau[i][j] = ' ';
} // fin recommence
【问题讨论】:
-
有什么问题?
-
[错误] 不能在没有对象的情况下调用成员函数 'void TicTacToe::affichTab() const'
-
错误只是它所说的。这里
TicTacToe::affichTab();你试图在没有对象的情况下调用函数。将方法设为静态或在对象上调用它 -
那里有很多格式问题,括号不加起来,
TicTacToe::affichTab();是最少的问题
标签: c++ tic-tac-toe