从双指针数组中读取- NULL
Reading from double array of pointers - NULL
我的方法替换双数组_board中的单元格。替换后,它将单元格设置为NULL。
在下一次调用设置为NULL的单元格时,它不会将其识别为NULL。
((_board [location.getX ()] [location.getY ()) = = NULL))
继续执行方法然后读取垃圾
什么错了吗?
void Board::MovePiece(Point location, Move m) throw (GameEndException, OutOfBoundsException, InvalidMoveException, NonEmptySquareException)
{
int i,j;
bool flag1,flag2;
if **(_board[location.getX()][location.getY()]==NULL)**{
InvalidMoveException IO;
throw IO;}
if ((_board[location.getX()][location.getY()]->IsValidMove(m)==false)||(_board[location.getX()][location.getY()]->getPlayerNum()!=GetTurn())) {
InvalidMoveException IO;
throw IO;}
if (_board[location.getDestination(m).getX()][location.getDestination(m).getY()]!=NULL) {
if (_board[location.getDestination(m).getX()][location.getDestination(m).getY()]->getPlayerNum()==GetTurn()){
NonEmptySquareException IO;
throw IO;}}
Point tmp=location.getDestination(m);
_board[tmp.getX()][tmp.getY()]=_board[location.getX()][location.getY()]->Clone();
delete _board[location.getX()][location.getY()];
_board[location.getX()][location.getY()]=NULL;
_lastM=m;
_lastP=location;
flag1=false;
flag2=false;
for (i=0;i<BOARD_SIZE;i++){
for (j=0;j<BOARD_SIZE;j++){
if(_board[i][j]!=NULL){
if (_board[i][j]->getPlayerNum()==ONE) flag1=true;
if (_board[i][j]->getPlayerNum()==TWO) flag2=true;
}}}
if ((flag1==false)||(flag2==false)){
GameEndException IO;
throw IO;}
}
这里delete _board[location.getX()][location.getY()];
已删除位置,您正在尝试访问已删除的内存位置。
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- 使用新行和不使用新行读取文件
- 读取文件并输入到矢量中
- 用c++从输入文件中读取另一行
- 读取文件的最后一行并输入到链接列表时出错
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 无法找到/读取配置文件.conf-FileIOException
- 如何使用Luacneneneba API正确读取字符串和表参数
- C++将文本文件中的数据读取到结构数组中
- c++ 结构指针在初始化为 NULL 时无法读取内存
- 在读取 Visual C++ 中的二进制文件(而不是其他编译器)后,每隔一个字符都是 NULL
- C++访问读取位置时发生冲突,类此指针为NULL
- 在 Matlab .mat 文件中读取:变量的秩和变暗正确,但数据为 NULL
- Delphi - 从 dll 调用转换(读取)C++ NULL 终止数组
- 同时使用POSIX从SERIAL读取null
- c++中的.get()在读取文件时是否返回null ?
- 从双指针数组中读取- NULL
- c++程序在读取NULL引用时崩溃
- 如何在ADO中读取NULL值
- 从 arduino 读取到 c++ 程序时继续接收 NULL