w*****z 发帖数: 6 | 1 我在做一个Qt的课题,需要链表操作界面化。算法这部分只是普通的C++,但是节点不
能够用struct,一定要用class。我在node.h中声明了两个指针,*previous和*next。链
表里面有Node* first和Node* current。请问我在链表的Deconstrucotr(LinkedList::
~LinkedList())中应该写些什么?我写的是:
C/C++ code
Node::~Node() {
previous = NULL;
next = NULL;
}
C/C++ code
LinkedList::~LinkedList() {
current = first;
while(current!=NULL){
first = current->next;
delete current;
current = NULL;
current = first;
}
current = NULL;
first = NULL;
}
然后试运行时Win | c******g 发帖数: 71 | 2 For class, it first run Node::~Node(), and then delete the memory the
current node holds. | w*****z 发帖数: 6 | 3 谢谢,那么还会有什么问题会引起Windows的报错呢? | h**k 发帖数: 3368 | 4 具体什么错误?
哪条语句出的问题?
另外,你不用在destructor里把所有指针型成员变量赋值成null。 |
|