C++/g++cygwin_exception::open_stackdumpfile:将堆栈跟踪转储到*.exe.st

C++/g++ cygwin_exception::open_stackdumpfile: Dumping stack trace to *.exe.stackdump

本文关键字:转储 跟踪 st exe 堆栈 stackdumpfile g++cygwin exception open C++      更新时间:2023-10-16

这是我在Airport.cpp中的主要内容:

#include <iostream>
#include "Airport_Queue.h"
#include "Airplane.h"
#include <stdlib.h>
int main(){
    Airplane *b = new Airplane(true);
    (*b).come();
    (*b).go();
    std::cout << "........." << std::endl;
    Airport_Queue *landing_queue = new Airport_Queue(5);
    Airplane *a0 = new Airplane(true);
    (*landing_queue).enqueue(a0); //error here
    //(*landing_queue).dequeue();
return 0;

这是我的Airport_Queue.cpp

#include "Airport_Queue.h"
Airport_Queue::Airport_Queue(unsigned n){
    Airplane** a = new Airplane*[n];
    capacity = n;
    size = 0;
    head = tail = 0;
}
Airport_Queue::~Airport_Queue(){
    for (size_t i = 0; i < size; i++){
        delete a[i];
    }
    delete [] a;
}
void Airport_Queue::enqueue(Airplane* airplane){
    if (!(*this).isFull()){
        a[tail] = airplane;
        (*a[tail]).come();
        tail = (tail+1) % capacity;
        size++;
    }
    else{
        std::cerr << "Queue is full." << std::endl;
    }
}
Airplane* Airport_Queue::dequeue(){ 
    if (!(*this).isEmpty()){
        size_t x = head;
        (*a[head]).go();
        head = (head+1) % capacity;
        size--;
        return a[x];
    }
    else{
        std::cerr << "Queue is empty." << std::endl;
        return NULL;
    }   
}
bool Airport_Queue::isEmpty(){
    if (size == 0)
        return true;
    else
        return false;
}
bool Airport_Queue::isFull(){
    if (size == capacity)
        return true;
    else
        return false;
}
int Airport_Queue::getSize(){
    return size;
}

我还有一门课叫飞机。我用来编译和链接的命令是g++ -std=c+11 -Wall -g -o airport Airport.cpp Airplane.cpp Airport_Queue.cpp如何修复此运行时错误?错误是当我调用enqueue时。然后我得到

4[main]airport 3796 cygwin_exception::open_stackdumpfile:将堆栈跟踪转储到airport.exe.stackdump

求你了。谢谢你。

我看到的问题:

  1. 您有一个成员变量size。你需要两个——capacitysize

  2. Airport_Queue::Airport_Queue

    Airport_Queue::Airport_Queue(unsigned size){
        Airplane** a = new Airplane*[size];
        size = 0; // This is the argument, not the member variable.
                  // The member variable remains uninitialized.
        head = tail = 0;
    }
    

    您需要:

    Airport_Queue::Airport_Queue(unsigned size){
        Airplane** a = new Airplane*[size];
        this->capacity = size;
        this->size = 0;            
        head = tail = 0;
    }
    
  3. Airport_Queue::~Airport_Queue

    Airport_Queue::~Airport_Queue(){
        for (size_t i = 0; i < sizeof(a); i++){
            // sizeof(a) does not give you the number of elements
            // in the array. It just gives you the size of the pointer.
            delete a[i];
        }
        delete [] a;
    }
    

您需要:

    Airport_Queue::~Airport_Queue(){
        for (size_t i = 0; i < this->size; i++){
            delete a[i];
        }
        delete [] a;
    }
  1. Airport_Queue::enqueue

    根据析构函数的逻辑,需要更改以下行。

    tail = (tail+1) % sizeof(a);
    

    更改为:

    tail = (tail+1) % capacity;
    
  2. In In Airport_Queue::dequeue

    您有一个类似于上面的错误。更改线路

    head = (head+1) % sizeof(a);
    

    head = (head+1) % capacity;
    
  3. Airport_Queue::isFull

    更改线路

    if (size == sizeof(a))
    

    if (size == capacity)
    

我希望这能解决你的大部分问题。如果有我错过的,希望你能找到。