【发布时间】:2015-12-23 01:19:36
【问题描述】:
我正在尝试使用 OOP 制作井字游戏,但我遇到了问题。当试图制作一个总共有 9 个方格并且所有方格都为空的游戏板时,我执行以下操作。
主要
#include "stdafx.h"
#include <vector>
int main()
{
char empty = ' '; //Empty square on playing board
const int numbOfSquares = 9; //Total amount of squares on board
std::vector<char> board(numbOfSquares, empty); // The playing board
return 0;
}
在我的董事会课程中,我正在尝试做同样的事情,但它的工作方式不同。
Board.h
#pragma once
#include <vector>
class Board
{
private:
const char empty = ' '; //Empty square on game board
const int numbOfSquares = 9; //Number of squares on the board
std::vector<char> board(numbOfSquares, empty); //The playing board
public:
};
说“numbOfSquares”和“empty”不是类型名称时发生错误。我想我理解这个错误信息,但我不确定如何解决它。我可以 - 重载,是这个术语 - 成员函数中的 board 变量吗?
我完全不知道该怎么做,希望得到一些帮助。感谢您的时间。
【问题讨论】:
标签: c++ oop console-application