gpt4 book ai didi

c++ - 程序意外终止 C++

转载 作者:行者123 更新时间:2023-11-28 01:49:30 24 4
gpt4 key购买 nike

该程序的目标是模拟具有 6 个“医生队列”的医疗综合体。我试着让它足够接近我已经完成的 Java 版本(必须使用 3 种语言)。此时,当我运行 DequeuePatientsListPatients 方法时,程序意外终止,没有错误。我试过调试器,但 Eclipse 忽略了我所有的断点。为什么它会终止?

ListPatients方法在Driver类中全部如下:

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;
  1. 如果函数被调用则在这个循环中终止

     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

中减去 1
for (x = 0; x<Length;x++) {
ComplexArray[x-1] = Node();
ComplexArray[x - 1].Modify(Current);
Current = Current->Next;
}

下标错误是 C/C++ 中的硬崩溃。

关于c++ - 程序意外终止 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43569272/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com