【问题标题】:C++/g++ cygwin_exception::open_stackdumpfile: Dumping stack trace to *.exe.stackdumpC++/g++ cygwin_exception::open_stackdumpfile:将堆栈跟踪转储到 *.exe.stackdump
【发布时间】:2015-04-25 14:59:58
【问题描述】:

这是我在 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)保留原始代码,然后在底部添加更新的代码,或者(2)使用更新的代码创建一个全新的帖子。

标签: c++ c++11 g++ cygwin


【解决方案1】:

我看到的问题:

  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. Airport_Queue::dequeue

    您遇到与上述类似的错误。换行

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

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

    换行

    if (size == sizeof(a))
    

    if (size == capacity)
    

我希望这可以解决您的大部分问题。如果有什么我遗漏的,希望你能找到它们。

【讨论】:

  • 谢谢。我修复了所有这些,但仍然有同样的错误。我将更新帖子中的代码,以便您查看。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-02
  • 1970-01-01
  • 2020-12-04
  • 2019-08-06
  • 2013-10-06
  • 2017-12-31
相关资源
最近更新 更多