我有一個功能「JOUER」的小問題。 我已經過了幾天的工作,但我看不到問題所在。 主要問題是:[錯誤]在'char'之前的'int'和[Error]預期的primary-expression之前預期的primary-expression。 下面是代碼:我在C++中的TicTacToe遊戲中的一個函數
#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
什麼問題? – Rakete1111
[錯誤]無法調用成員函數'void TicTacToe :: affichTab()const'without object – Sorel
錯誤只是表示它說的是什麼。這裏'TicTacToe :: affichTab();'你正試圖調用沒有對象的函數。要麼使方法靜態或在對象上調用它 – user463035818