关于一个指针数组的delete的问题,有兴趣的快来,在线给分!!

jenycheng 2003-08-20 07:50:29
这是我定义的指针数组:
const int MAX_LINE = 5346;
CMyLibForm BucketArray[ MAX_LINE ];
CMyLibForm类如下:
class CMyLibForm
{
public: //对自身的操作;
void SetKey(CString&);
CString GetKey()const;

void SetNext(CMyNodeType *);
CMyNodeType * GetNext()const;

public: //对节点的操作
void CreactNode(); //在链表中增加结点
void EraseNode();//删除一个结点;

void SetWord(CString&); //设置word的值;
CString GetWord()const; //读取链表中头指针所指节点的word;
void SetHCode(CString&);
CString GetHCode();
void SetLCode(CString&);
CString GetLCode();
private:
CString key;
CMyNodeType * next;
CMyNodeType * innode;
CMyNodeType * endnode;
};

class CMyNodeType
{
public:
CMyNodeType();
virtual ~CMyNodeType();

public:
void SetWord(CString &);
CString GetWord()const;

void SetHCode(CString &);
CString GetHCode()const;

void SetLCode(CString &);
CString GetLCode()const;

void SetNext(CMyNodeType *);
CMyNodeType* GetNext()const;

private:

CString word;
CString hcode;
CString lcode;
CMyNodeType* next;

};
在用析构函数删除innode 结点时,运行到BucketArray[ 5340];就出错,提示
没有innode 这个指针,这是怎么会事?
请各位帮忙!!!!
...全文
58 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
zerospace01 2003-09-15
  • 打赏
  • 举报
回复
操作码有问题
lybapple 2003-08-23
  • 打赏
  • 举报
回复
好像没有问题的。
jenycheng 2003-08-23
  • 打赏
  • 举报
回复
一定是操作码的问题
jenycheng 2003-08-23
  • 打赏
  • 举报
回复
这段代码没有问题,你可以把 delete( innode );去掉,然后,打印出 innode 和 next 的值
看看有没有什么问题。

一定是你的操作码有问题
sevecol 2003-08-20
  • 打赏
  • 举报
回复
按上面的执行,没有问题
sevecol 2003-08-20
  • 打赏
  • 举报
回复
class CMyNodeType;

class CMyLibForm
{
public: //对自身的操作;
CMyLibForm();
~CMyLibForm();

void SetKey(string&);
string GetKey()const;

void SetNext(CMyNodeType *t)
{
next=t;
}
CMyNodeType * GetNext()const;

public: //对节点的操作
void CreactNode(); //在链表中增加结点
void EraseNode();//删除一个结点;

void SetWord(string&); //设置word的值;
string GetWord()const; //读取链表中头指针所指节点的word;
void SetHCode(string&);
string GetHCode();
void SetLCode(string&);
string GetLCode();
private:
string key;
CMyNodeType* next;
CMyNodeType* innode;
CMyNodeType* endnode;
};

class CMyNodeType
{
public:
CMyNodeType();
virtual ~CMyNodeType(){};

public:
void SetWord(string &t)
{
word=t;
}
string GetWord()const;

void SetHCode(string &t)
{
hcode=t;
}
string GetHCode()const;

void SetLCode(string &t)
{
lcode=t;
}
string GetLCode()const;

void SetNext(CMyNodeType *t)
{
next=t;
}
CMyNodeType* GetNext()const;

private:

string word;
string hcode;
string lcode;
CMyNodeType* next;

};


CMyLibForm::CMyLibForm()
{
key.empty();
innode = new(CMyNodeType);
next = innode;
endnode = new(CMyNodeType);
innode->SetNext(endnode);

};
CMyLibForm::~CMyLibForm()
{
static int i = 0;
delete (endnode);
endnode = NULL;
cout << "delete innode ! " << i++ << endl;
delete (innode);
cout << "innode deleted !" << endl;
innode = NULL;
next = NULL;
};

CMyNodeType::CMyNodeType()
{
string nulch("#");
SetWord(nulch);
SetHCode(nulch);
SetLCode(nulch);
SetNext(NULL);

};

CMyLibForm *BucketArray=new CMyLibForm[ MAX_LINE ];

delete[] BucketArray;
jenycheng 2003-08-20
  • 打赏
  • 举报
回复
出错是在 CMyLibForm::~CMyLibForm()
删除 innode 的是时候
而且,是在删除 BucketArray[ 5340];的innode 指针时
sevecol 2003-08-20
  • 打赏
  • 举报
回复
我这里能完全执行.

你是不是执行了别的什么操作?
jenycheng 2003-08-20
  • 打赏
  • 举报
回复
CMyNodeType里面是空的
setnext就是一个赋值
catcafee 2003-08-20
  • 打赏
  • 举报
回复
是不是你在CMyNodeType的析构函数里做了什么处理?
catcafee 2003-08-20
  • 打赏
  • 举报
回复
setnext函数怎么实现的
vsfan 2003-08-20
  • 打赏
  • 举报
回复
建议改用标准链表
catcafee 2003-08-20
  • 打赏
  • 举报
回复
把析构函数的代码贴出来
jenycheng 2003-08-20
  • 打赏
  • 举报
回复
CMyLibForm::CMyLibForm()
{
key.Empty();
innode = new(CMyNodeType);
next = innode;
endnode = new(CMyNodeType);
innode->SetNext(endnode);

}
CMyLibForm::~CMyLibForm()
{
static int i = 0;
delete (endnode);
endnode = NULL;
cout << "delete innode ! " << i++ << endl;
delete (innode);
cout << "innode deleted !" << endl;
innode = NULL;
next = NULL;
}

CMyNodeType::CMyNodeType()
{
CString nulch('#');
SetWord(nulch);
SetHCode(nulch);
SetLCode(nulch);
SetNext(NULL);

}
5956 2003-08-20
  • 打赏
  • 举报
回复
把类的实现也贴出来吧
odaliu 2003-08-20
  • 打赏
  • 举报
回复
构造函数的内容是什么啊?
sevecol 2003-08-20
  • 打赏
  • 举报
回复
把你的操作代码也贴出来吧

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧