我正在学习C ++,并尝试制作一个Tic Tac Toe的小游戏。但是我继续得到非标准语法C3867。使用“&”创建要记住的指针。
这是我的TicTacToe.h:
#pragma once
#include <iostream>
using namespace std;
class TicTacToe
{
public:
TicTacToe();
string getName1();
string getName2();
void printBoard();
void clearBoard();
void setName1(string player1Name);
void setName2(string player2Name);
void setSign1(string player1Sign);
void setSign2(string player2Sign, string player1Sign);
void playGame(string player1Name, string player2Name,string player1Sign,string player2Sign);
void player1Move(string coordX);
void player1Turn();
void player2Turn();
private:
char Board[3][3];
string _player1Name;
string _player2Name;
string _player1Sign;
string _player2Sign;
string _coordX;
string _coordY;
};
这是我的TicTacToe.cpp:
#include "TicTacToe.h"
#include <iostream>
#include <string>
TicTacToe::TicTacToe() {}
void TicTacToe::playGame(string player1Name, string player2Name,
string player1Sign, string player2Sign) {
TicTacToe Board;
Board.setName1(player1Name);
Board.setSign1(player1Sign);
Board.setName2(player2Name);
Board.setSign2(player1Sign, player2Sign);
Board.clearBoard();
Board.printBoard();
}
void TicTacToe::printBoard() {
cout << " |1|2|3|\n";
for (int i = 0; i < 3; i++) {
cout << "--------\n";
cout << i + 1 << "|" << Board[i][0] << "|" << Board[i][1] << "|"
<< Board[i][2] << "|" << endl;
}
}
void TicTacToe::clearBoard() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
Board[i][j] = ' ';
}
}
}
void TicTacToe::setName1(string player1Name) {
cout << "Enter your name, player 1: \n";
cin >> player1Name;
_player1Name = player1Name;
}
void TicTacToe::setName2(string player2Name) {
cout << "Enter your name, player 2: \n";
cin >> player2Name;
_player2Name = player2Name;
}
string TicTacToe::getName1() { return _player1Name; }
string TicTacToe::getName2() { return _player2Name; }
我已经尝试了其他所有有关此错误的问题,但它们没有起作用。您如何解决此错误?
皈依舞
撒科打诨
相关分类