好的,所以我将我的代码简化到最低限度,以便发布的列表不会很长。问题是当我完成程序时代码崩溃,即调用了析构函数。因为点类在 ptlist 类中,而板类中的 ptlist 我认为我必须在删除析构函数中的对象时进行一些链接,但是在我到达 if(item != NULL) 行后它崩溃了ptlist 的析构函数...由于某种原因,它既不输入 if 子句也不输入 else 子句.. 不知道为什么.. 无论如何,这是我程序的精简代码:
[编辑] 感谢大家,我修复了代码,它现在运行完美。谢谢你们
#include <windows.h> //include all the basics
#include <tchar.h> //string and other mapping macros
#include <string>
#include <ctime>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
using namespace std;
class point
{
unsigned x;
unsigned y;
int id;
int type;
bool covered;
int maze;
public:
point(){x = 0; y = 0; id = 0; type = -1; covered = true; maze = 0;}
~point(){x = 0; y = 0; id = 0; type = 0; covered = true; maze = 0;}
};
class ptlist
{
point ** item;
int length;
int itemmax;
public:
ptlist(){item = NULL; length = 0; itemmax = 0;}
ptlist(int imax);
~ptlist();
};
ptlist::ptlist(int imax)
{
item = new point *[imax];
length = 0;
itemmax = imax;
}
ptlist::~ptlist()
{
delete [] item;
}
class board
{
ptlist *wall;
ptlist *path;
public:
board(){wall = new ptlist(1); path = new ptlist(1);}
~board(){delete wall; delete path;}
};