저는 C++을 배우고 Tic Tac Toe의 작은 게임을 만들려고합니다. 그러나 나는 비표준 문법 인 C3867을 계속 사용하고있다. '&'을 사용하여 기억할 포인터를 만듭니다. 여기Visual Studio 2015 "비표준 구문; '&'를 사용하여 멤버에 대한 포인터를 만듭니다.
#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;
}
void TicTacToe::setSign1(string player1Sign)
{
cout << "What will you sign be?(X/O)\n";
cin >> player1Sign;
if (player1Sign != "X" && player1Sign != "O" && player1Sign != "x" && player1Sign != "o")
{
cout << "Invalid input, try again.\n";
cin >> player1Sign;
}
_player1Sign = player1Sign;
}
void TicTacToe::setSign2(string player2Sign, string player1Sign)
{
cout << "What will you sign be?(X/O)\n";
cin >> player2Sign;
if (player2Sign != "X" && player2Sign != "O" && player2Sign != "x" && player2Sign != "o" || player2Sign == player1Sign)
{
cout << "Invalid input, try again.\n";
cin >> player2Sign;
}
_player2Sign = player2Sign;
}
void TicTacToe::player1Move(string coordX) //ERROR
{
cout << "Enter X: " << endl;
cin >> coordX;
_coordX = coordX;
}
void TicTacToe::player1Turn()
{
cout << "Player 1 turn !\n";
TicTacToe Board;
Board.player1Move;
}
void TicTacToe::player2Turn()
{
cout << "Player 2 turn !\n";
TicTacToe Board;
Board.player1Move;
}
이 내 TicTacToe.h입니다. 이 오류를 어떻게 수정합니까?
[mcve]를 생성하십시오. 최소한의 강조. – Barry
문제를 일으키는 라인에 플래그를 지정하여 우리의 삶을 좀 더 쉽게 만들어야합니다! – Sean
당신이 'Board.player1Move'라고 말하면, 그것을 함수로 부르면됩니다. 또한 전달하지 않는 매개 변수 (문자열)를 사용합니다. – Sean