好吧,我簡化我的代碼到最低限度,以便它不是一個很長的列表發佈..問題是代碼崩潰時,我完成程序,即析構函數被調用。因爲point類是在ptlist類中的,並且board類中的ptlist我認爲我必須如何鏈接,然後在析構函數中刪除對象時它會崩潰,但在到達if(item!= NULL)行後崩潰ptlist的析構函數...它不會因爲某些原因不輸入if子句和else子句..不知道爲什麼..反正繼承了我的程序的細化代碼:如何在C++中以深度順序破壞幾個類
[編輯]我感謝你們所有人修復了代碼,現在它完美運行。謝謝大家
#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;}
};
這是* not * C. – 2013-07-13 06:13:22
在你的'point'tor處有一些複製和浪費錯誤。 – dyp
這段代碼如何編譯?我的意思是'〜board()刪除[]牆;刪除[]路徑;}'是不正確的語法,你錯過了大括號。在課堂結束時,你還有一個隨機的'* this;'。另外,規則是如果你'刪除'你刪除[]'''''''''所以你應該修復你的析構函數。 – Borgleader