我试图破坏一个全局结构数组。
然而,它在Visual Studio 2013中创建了以下消息并崩溃。
消息:
“调试断言失败”\u BLOCK\u TYPE\u有效(pHead->nBlockUse)
template <typename T>
struct List {
struct ListNode {
ListNode() : item(0), next(0) {}
ListNode(T x) : item(x), next(0) {}
T item;
ListNode* next;
};
T operator[](int idx);
void insert(T x);
T get(int idx);
void print();
List() : head(0),tail(0),size(0) {}
ListNode* head;
ListNode* tail;
int size;
~List() {
ListNode* h = head;
while(h) {
ListNode* n = h->next;
delete h;
h = n;
}
head = NULL;
tail = NULL;
size = 0;
}
};
列表::插入()
template <typename T>
void List<T>::insert(T x) {
if(head == NULL) {
head = new ListNode(x);
tail = head;
} else {
tail->next = new ListNode(x);
tail = tail->next;
}
size++;
}
List<int> a[1001];
下面是我用来分解列表结构的全局数组的代码:
loop(i,0,N+1) {
delete &a[i];
}