C++ 从堆中分配时检测到严重错误

C++ 从堆中分配时检测到严重错误,c++,dynamic,linked-list,heap,access-violation,C++,Dynamic,Linked List,Heap,Access Violation,在我的程序中,我需要制作一个链表,但链表的大小(节点数)是在编译时定义的。“newcustomer.numT”变量是将创建的节点数。 要做到这一点,我认为应该有一个指针数组,然后根据每个指针从堆中请求内存。但是,不幸的是,我也不知道数组的大小。我也动态地创建了它。“transactionn”是在单个节点中保存值的结构 transactionn **asd; asd = new transactionn*[newcustomer.numT]; //I created array of p

在我的程序中,我需要制作一个链表,但链表的大小(节点数)是在编译时定义的。“newcustomer.numT”变量是将创建的节点数。 要做到这一点,我认为应该有一个指针数组,然后根据每个指针从堆中请求内存。但是,不幸的是,我也不知道数组的大小。我也动态地创建了它。“transactionn”是在单个节点中保存值的结构

 transactionn **asd;
 asd = new transactionn*[newcustomer.numT];    //I created array of pointers
 for (int k = 0; k<newcustomer.numT; k++){
    asd[k] = new transactionn;  //Allocating a node for each pointer in the array
 } //End of the "node creating" 

 newcustomer.trahead = asd[0]; //Assign head to the first node

//Connecting nodes in the linked list to eachother
for (int z = 0; z < (newcustomer.numT)-1; z++){
    asd[z]->next = asd[z + 1];     
}
asd[newcustomer.numT]->next = NULL; //Set the next of the last node to NULL
它会在这一行触发一个断点:

asd[k] = new transactionn;
我做错了什么

编辑:我更正了上一个索引,当时它是:

asd[(newcustomer.numT)-1]->next = NULL;
当我把这些代码编译成一个完整的程序时,并没有错误,程序也不会崩溃。当我将此功能实现到我的主项目时,程序再次崩溃。严重错误

编辑2:这些台词是正确的。错误源是由于它们从其他函数获得的值

asd = new transactionn*[newcustomer.numT];    //I created array of pointers
//...
asd[newcustomer.numT]->next = NULL; //Set the next of the last node to NULL

数组溢出。
asd
指向的数组的最后一个索引是
newcustomer.numT-1

它表示“堆已损坏”。标准错误当你抛出原始指针时,当然,错误位于其他地方。那么这些行中没有错误吗@汉帕桑
asd = new transactionn*[newcustomer.numT];    //I created array of pointers
//...
asd[newcustomer.numT]->next = NULL; //Set the next of the last node to NULL