It's a memory problem.



  • Turns out with a mistake.

    An unprocessed exception to 0x779F3E28 in CourseProject.exe: Microsoft C++: std:bad_alloc at memory 0x001DE598.

    On the line:

    PP[i + 1] = tmp; 
    

    That's the whole sorting code.

    void sort(Plane* PP, int count)
    {
        for (int i = 0; i < count; i++)
            PP[i].fuel_on_one_passangers();
    
    for (int i = 0; i &lt; count; i++)
    {
        if (PP[i + 1].price &lt; PP[i].price)
        {
            Plane tmp = PP[i];
            PP[i] = PP[i + 1];
            PP[i + 1] = tmp;
        }
    }
    

    }

    Here. https://cloud.mail.ru/public/KS3K/nKvm6W6eW Total project code



  • The function has undetermined behaviour, because there is an attempt to remembrance outside the body.

    for (int i = 0; i < count; i++)
    {
        if (PP[i + 1].price < PP[i].price)
            ^^^^^^^^^  
        {
            Plane tmp = PP[i];
            PP[i] = PP[i + 1];
                    ^^^^^^^^^
            PP[i + 1] = tmp;
            ^^^^^^^^^ 
        }
    }
    

    If the mass has count elements, i equal to count-1 expression PP[i + 1] tries to change the non-existent element with the index countas the permissible range of indices [0, count - 1]

    Also bear in mind that your function does not sort anything. It's just an element of the field max. price moving to the extreme position of the mass.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2