C++/g++cygwin_exception::open_stackdumpfile:将堆栈跟踪转储到*.exe.st
C++/g++ cygwin_exception::open_stackdumpfile: Dumping stack trace to *.exe.stackdump
这是我在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
求你了。谢谢你。
我看到的问题:
-
您有一个成员变量
size
。你需要两个——capacity
和size
。 -
在
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; }
-
在
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;
}
在
Airport_Queue::enqueue
中根据析构函数的逻辑,需要更改以下行。
tail = (tail+1) % sizeof(a);
更改为:
tail = (tail+1) % capacity;
In In
Airport_Queue::dequeue
您有一个类似于上面的错误。更改线路
head = (head+1) % sizeof(a);
至
head = (head+1) % capacity;
在
Airport_Queue::isFull
中更改线路
if (size == sizeof(a))
至
if (size == capacity)
我希望这能解决你的大部分问题。如果有我错过的,希望你能找到。
相关文章:
- 分段故障(堆芯转储)矢量
- Cppcheck生成xml转储文件
- 如何找出GDB的SIGTRAP核心转储的根本原因
- C++映射分割错误(核心转储)
- 在c++中初始化矩阵时出现分段错误(核心转储)
- 在c++中键入向量中的所有值后,得到分段错误(核心转储)
- 浮点异常(核心转储)#694457
- 分段错误(核心转储)但无法弄清楚
- 链接到libkcapi时没有核心转储
- 检测到堆栈粉碎:已终止 中止(核心已转储)
- 正在处理故障(堆芯转储)
- 分段错误(核心转储) - 使用 SavedModel 的 Tensorflow C++ API 进行推断
- cygwin_exception::open_stackdumpfile:将堆栈跟踪转储到 class4.exe.sta
- WinDbg 不显示某些小型转储文件的完整堆栈跟踪
- 当外部源代码中发生异常时,无法正确使用自创建的小型转储文件的堆栈跟踪
- C++/g++cygwin_exception::open_stackdumpfile:将堆栈跟踪转储到*.exe.st
- Linux Stack 跟踪转储
- 无法使用sqlite3数据库表的所有行中的数据填充列表,错误:跟踪/断点陷阱(核心转储)
- 用于从堆栈转储和.elf文件中提取FreeRTOS/ARM/ c++堆栈跟踪的工具
- cygwin_exception::open_stackdumpfile:将堆栈跟踪转储到*.exe.stackdump