나는 다음과 같은 코드로 "분할 오류 (코어 덤프)"런타임 오류가 점점 오전 : 나는 delete list;
라인 아래로 오류를 좁혀분할 오류 C++
#include <iostream>
#include "Student.h"
#include "SortedList.h"
using namespace std;
#define BOUNDS 100
int main() {
SortedList *list = new SortedList(); // points to the sorted list object
Student *create[BOUNDS]; // array to hold 100 student objects
int num = 100000; // holds different ID numbers
// fills an array with 100 students of various ID numbers
for (int i = 0; i < BOUNDS; i++) {
create[i] = new Student(num);
num += 10;
}
// insert all students into the sorted list
for (int i = 0; i < BOUNDS; i++)
list->insert(create[i]);
// individually deletes each student
num = 100000;
for (int i = 0; i < BOUNDS; i++) {
delete list->find(num);
num += 10;
}
// insert all students into the sorted list
for (int i = 0; i < BOUNDS; i++)
list->insert(create[i]);
num = 100000;
for (int i = 0; i < BOUNDS; i++) {
list->remove(num);
num += 10;
}
cout << "test2" << endl;
delete list;
return 0;
}
을 (또는 둘 중 하나가 먼저 발생). 나는 왜 이것이 이것이 무엇이며 어떻게 고칠 수 있을지 궁금해하고있다. 이 문제에 대한 통찰력이 유용 할 것입니다.
당신은 유닉스 시스템에서 이것을 실행하는 것처럼 보입니다. 그러므로 Valgrind를 사용하십시오;) – 0xC0000022L
"// 다양한 ID 번호의 100 명의 학생으로 배열 채우기"이 루프는이 주석이 말하는 것을하지 않습니다. –
참고로, 누군가가'namespace std;를 사용할 때마다, 나는 강아지를 걷어 찼다. 가난한 강아지에 대해 다시 생각하기 전에 생각하십시오. – cHao