我正在为 connect 4 游戏编写一个类,当我去绘制棋盘时遇到问题,当我尝试引用我的 game_board 成员变量时,错误 EXC_BAD_ACCESS (code=1 access=0x0) 不断出现. 我究竟做错了什么?提前致谢。
#include "board.h"
#include <iostream>
using namespace std;
Board::Board()
{
char** game_board=new char*[SIZEX];
for(int i=0; i<SIZEX; i++)
game_board[i]=new char[SIZEY];
for (int i=0;i<SIZEX;i++)
{
for (int j=0;j<SIZEY;j++)
{
game_board[i][j]=' ';
}
}
};
void Board::draw()
{
for (int j=0; j<SIZEY;++j )
{
cout<<"|---+---+---+---+---+---+---|\n";
for (int i=0; i<SIZEX;++i)
{
cout<<"| "<<game_board[i][j]<<" ";
}
cout<<"|\n";
}
cout<<"|---+---+---+---+---+---+---|\n";
};
Board::~Board()
{
for(int i=0; i<SIZEX; i++)
delete [] game_board[i];
delete []game_board;
};