Hi if anybody could advise how to correctly do this. Basically I'm trying to make a class variable called Board who holds in it a two dimensional array of ChessPiece instances.
#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;
}
Pretty basic thing I'm missing here really, but I can't seem to figure it out. Thank you!
std::vector<std::vector<ChessPiece>>, or even more simplystd::vector<ChessPiece>and track the index as row/column using simple multiplication.