问题描述
我正在尝试创建一个国际象棋引擎,所以我创建了一个 Board 类(只显示 h 文件,因为实现非常简单):
class Board {
private:
Piece* board[SIZE][SIZE];
bool turn;
public:
Board();
Piece* getBoard() const;
void printBoard() const;
};
这个想法是制作一个充满不同部分的二维数组。 显然,我还创建了一个 Piece 类(所有其他部分的父类):
class Piece {
protected:
bool color;
int PosX;
int PosY;
public:
Piece(const bool c,const int x,const int y);
~Piece();
virtual int tryMove(int toX,int toY,Board &board) const = 0;
virtual char toChar() const = 0;
}
我创建了一个 EmptyPiece 类来尝试初始化数组,但我不知道如何用这些片段填充数组。
EmptyPiece 的 h 文件:
class EmptyPiece : protected Piece {
public:
EmptyPiece(const bool c,const int y);
char toChar() const;
int tryMove(int toX,Board& board) const;
};
这就是我尝试初始化数组的方式:
Board::Board()
{
turn = true;
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
board[i][j] = EmptyPiece(0,i,j);
}
}
}
导致错误:
E0413 no suitable conversion function from "EmptyPiece" to "Piece *" exists
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)