這裏是我的主要在Airport.cpp:C++/G ++ cygwin_exception :: open_stackdumpfile:轉儲堆棧跟蹤* .exe.stackdump
#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 [主]機場3796 cygwin_exception :: open_stackdumpfile:轉儲堆棧跟蹤airport.exe.stackdump
請。謝謝你。
不要這樣做到你的文章。當你閱讀我的答案時,它將不再有意義。你應該做的是(1)保留原始代碼,然後在底部添加更新的代碼,或者(2)用更新後的代碼創建一個全新的帖子。 – 2015-02-24 05:15:16