程序意外终止C
Program Terminates unexpectedly C++
该程序的目的是模拟用6个"医生队列"的医学综合体。我试图将其保持足够近的距离与我完成的Java版本(必须用3种语言执行此操作(。此时,当我运行DequeuePatients
和ListPatients
方法时,程序出乎意料地终止而没有错误。我尝试了调试器,但是Eclipse忽略了我所有的断点。为什么它终止?
listApatients方法在驱动程序类中均为:
void ListPatients() {
int x, QueueChoice = 0;
bool exit = false;``
while (!exit) {
for (x = 1; x <= MAX; x++) {
cout << x << ": " << Doctor[x - 1] << "n";
} // end-for
cout << "Choose a Queue to List From";
cin >> QueueChoice;
if (OpenFlag[QueueChoice - 1] == true) { //open flag for each queue
int i = Complex[QueueChoice - 1]->GetSize();//Global array of queues
//cout <<i<<endl;
如果函数称为
,则在此循环中终止for (x = 1; x <= i; x++) { Patient This = Complex[QueueChoice-1]->GetInfo(x); //Program Terminates here cout << x<< ": " << endl;//This.ID_Number; //<<Complex[QueueChoice - 1]->GetInfo(x + 1).PrintMe() } // end-for } // end-if cout << "Press 1 to List Another Queue, press 2 to exit"; cin >> x; switch (x) { case 1: break; case 2: exit = true; break; }//switch } // end-while } // List Patients`
队列类GetInfo和toarray((:
/*Return Patient info from each Node*/
Patient Queue::GetInfo(int Pos) {
Node* ComplexArray= new Node[Length];
ComplexArray = this->toArray();
return ComplexArray[Pos - 1].Info;
}
// The toArray method
Node* Queue::toArray() {
// Copy the information in each node to an array and return the array.
int x = Length;
Node ComplexArray[Length] ={} ;
Node* Current = new Node();
Current = Rear;`
for (x = 0; x<Length;x++) {
ComplexArray[x] = Node();
ComplexArray[x].Modify(Current);
Current = Current->Next;
}
return ComplexArray;
} // End of toArray method
节点中的修改方法:
void Node :: Modify(Node* ThisNode)
{
Info = ThisNode->Info;
Next = ThisNode->Next;
}
如果这是零基准,为什么从 x
for (x = 0; x<Length;x++) {
ComplexArray[x-1] = Node();
ComplexArray[x - 1].Modify(Current);
Current = Current->Next;
}
下标错误是C/C 中的硬崩溃。
问题是基本的,这是我宣布指针的方式,以及更改toArray
功能以返回患者指针(可以将其视为数组?(插入节点,而不仅仅是数组的第一个元素。
这导致Toarray返回一个节点指针,该实例Next
指针连续指向自身。
Queue Complex[6] = Queue(); //in driver class
Patient* ComplexArray[Length] = new Patient();//Queue Class GetInfo & toArray
我需要:
Queue* Complex = new Queue[MAX];
Patient* ComplexArray = new Patient[Length];
并更改了这些功能:
Patient Queue::GetInfo(int Pos) {
Patient* ComplexArray = new Patient[Length];
ComplexArray= toArray();
return ComplexArray[Pos - 1];
}
// Now returns Patient pointer of Node->Info to GetInfo
Patient* Queue::toArray() {
Node* Current;
int x;
Patient* ComplexArray = new Patient[Length];
Current = Rear;
for (x = 1; x <= Length; x++) {
ComplexArray[x-1] = Patient();
ComplexArray[x - 1].Modify(Current->Info);
Current = Current->Next;
}
return ComplexArray;
} // End of toArray method
相关文章:
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 在C++中对T*类型执行std::move的意外行为
- 多个文件的内存分配错误"在抛出 'std :: bad_alloc' what (): std :: bad_alloc 的实例后终止调用" [C++]
- 我收到以下错误:抛出'std::bad_alloc'实例后终止调用
- 使用取消引用的指针的多态性会产生意外的结果.为什么?
- 为什么这个 c++ 代码打印出长度 5,当我打印出字符串时,程序会自动终止?
- 处理除以零会导致<csignal>意外行为
- vscode下的Arduino代码出现意外编译错误
- 使用++运算符会导致意外的结果
- 套接字读取后,我在缓冲区中看到意外输入
- 在C 中,可以检测到线程的意外终止
- 程序意外终止C
- 设置终止和意外处理程序
- 如何在 Google 测试中抑制终止时 assert() 意外触发
- 程序在引入 catch 块后意外终止
- 程序不断调用意外和终止函数
- 当循环意外终止时(C/C++)
- 在数组中增加元素时进程意外终止
- 异常处理,c++中的意外终止符
- Windows服务在Windows7中意外终止