mardi 19 avril 2022

while(true) condition only works for once correctly and terminates [closed]

Hi I was doing my homework and needed write while loop creating same type of object with passing different instance. Here is my code

while(true){
        ComputerSystem * compSystem = new ComputerSystem (computerNumber, &allReq, allReq.getSize(), averageTimeHolder, resultText);
        computerNumber++;
    }

in this code block code just did not do anything and terminates without any problem. On the other hand the code below worked perfectly fine.

        ComputerSystem  compSystem(3, &allReq, allReq.getSize(), averageTimeHolder, resultText);

Which I did not understand. One more interesting thing that the code block

 while(true){
    ComputerSystem  compSystem(computerNumber, &allReq, allReq.getSize(), averageTimeHolder, resultText);
}

only works for one time and terminates. I thought that it is about constructor so here is my constructor

ComputerSystem::ComputerSystem(int computerNumber, AllRequests * allRequest, int requestSize, double * averageTimeHolder, string  * result) {
    averageTime = 0;
    resultString = "";
    systemTime = 1;
    this->allRequests = allRequest;
    this->computerNumber = computerNumber;
    this->requestSize = requestSize;
    createComputers();
    reqPRQ = new RequestPRQ(requestSize);

    cout << "Start is reached" << endl;
    start();
    *averageTimeHolder = double (averageTime  / requestSize);
    *result = resultString;

}

Why the while loop either do not work or only executes for one time?

Aucun commentaire:

Enregistrer un commentaire