嗨,如果有人可以建议如何正确地做到这一点。基本上,我正在尝试创建一个名为 Board 的类变量,其中包含 ChessPiece 实例的二维数组。
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
class ChessPiece
{
public:
char ToChar() { return '#'; };
};
class ChessBoard
{
int Size; //This means board is 8x8.
ChessPiece ** Board;
public:
ChessBoard();
int GetSize() { return Size; };
void PlotBoard();
};
ChessBoard::ChessBoard() {
Size = 8;
ChessPiece newBoard[Size][Size];
Board = newBoard; //Problem here!!! How do I make Board an 8x8 array of ChessPiece?
}
void ChessBoard::PlotBoard() {
int x, y;
for (x = 0; x < Size; x++) {
for (y = 0; y < Size; y++)
printf("%c", Board[x][y].ToChar());
}
}
int main()
{
// ChessBoard board;
// printf("%d", board.GetSize());
// board.PlotBoard();
ChessBoard * a = new ChessBoard();
return 0;
}
我真的在这里错过了非常基本的东西,但我似乎无法弄清楚。谢谢!