Here's my main in 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;
This is my Airport_Queue.cpp
#include "Airport_Queue.h"
Airport_Queue::Airport_Queue(unsigned size){
Airplane** a = new Airplane*[size];
size = 0;
head = tail = 0;
}
Airport_Queue::~Airport_Queue(){
for (size_t i = 0; i < sizeof(a); i++){
delete a[i];
}
delete [] a;
}
void Airport_Queue::enqueue(Airplane* airplane){
if (!(*this).isFull()){
a[tail] = airplane;
(*a[tail]).come();
tail = (tail+1) % sizeof(a);
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) % sizeof(a);
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 == sizeof(a))
return true;
else
return false;
}
int Airport_Queue::getSize(){
return size;
}
I also have a class called Airplane. The command I use to compile and link is g++ -std=c+11 -Wall -g -o airport Airport.cpp Airplane.cpp Airport_Queue.cpp How can I fix this run-time error? The error is when I call enqueue. Then I get
4 [main] airport 3796 cygwin_exception::open_stackdumpfile: Dumping stack trace to airport.exe.stackdump
Please. And thank you.
Aucun commentaire:
Enregistrer un commentaire