c++对象指针的优先级队列在运行时错误为无效堆
C++ Priority queue of object pointers at runtime error as invalid heap
我已经尝试在c++中实现一个优先队列大约5个小时了。
我不相信我的比较器函子在做它应该做的事,但是无论如何我也不知道为什么。
在Node类的底部,我有一个结构体CompareNode, Node类有一个返回int成员变量的函数。
class Node
{
public:
Node();
~Node();
Node(const Node &obj);
int GetX() const { return x; }
int GetY() const { return y; }
int GetG() const { return g; }
int GetH() const { return h; }
int GetF() const { return f; }
int GetTerrainPenalty() const { return terrainPenalty; }
bool GetOpenList() const { return openList; }
bool GetClosedList() const { return closedList; }
Node* GetParentNode() const { return parentNode; }
std::vector<Node*> const GetNeighbours() { return neighbours; }
void SetX(int x) { this->x = x; }
void SetY(int y) { this->y = y; }
void SetG(int g) { this->g = g; }
void SetH(int h) { this->h = h; }
void SetF(int f) { this->f = f; }
void SetTerrainPenalty(int t) { this->terrainPenalty = t; }
void SetOpenList(bool b) { this->openList = b; }
void SetClosedList(bool b) { this->closedList = b; }
void SetParentNode(Node* n) { this->parentNode = n; }
void SetNeighbours(std::vector<Node*> n) { this->neighbours = n; }
void AddNeighbour(Node* n) { neighbours.push_back(n); }
// Manahattan Distance
void CalculateH(Node* end);
void CalculateF();
private:
int x;
int y;
int g;
int h;
int f;
int terrainPenalty;
bool openList;
bool closedList;
Node* parentNode;
std::vector<Node*> neighbours;
};
struct CompareNode
{
bool operator()(const Node* lhs, const Node* rhs) const
{
return lhs->GetF() < rhs->GetF();
}
};
我在main.cpp中声明了优先级队列。
std::priority_queue<Node*, std::vector<Node*>, CompareNode> openList;
我得到一个调试断言失败错误,无效堆。
调试时,似乎当我调用openList.top()时,它没有返回正确的Node。
你知道我做错了什么吗?
我的通灵调试能力告诉我,由于您没有为您的Node
实现复制构造函数,因此您不小心将其复制到某个地方导致双删除
相关文章:
- 删除指向指针的指针是运行时错误吗
- c++中的指针和运行时错误
- 无法理解此 return 语句的功能,没有它就会发生运行时错误
- 在同一模拟中使用静脉和静脉_ inet内容时出现运行时错误
- 对单向链表进行排序时出现运行时错误
- 为什么此代码存在运行时错误?
- 你能解释一下什么运行时错误是如何解决它的吗?
- 为什么会出现 gettnig 运行时错误:加载类型为"_Bit_type"(stl_bvector.h) 的空指针?
- 为什么程序在 c++ 中迭代 emtpy 向量时会抛出运行时错误
- 运行时错误:引用绑定到类型为"int"的空指针
- 为什么当 vector 为空时会显示运行时错误?
- C++运行时错误与快速排序算法抛出堆栈转储错误
- 运行时错误:矢量下标超出范围:正在检查空集
- 分配给gslice_array会导致运行时错误
- C 运行时错误:Free():下一个大小无效(快速)
- QAbstractItemModel::endInsertRows:无效索引运行时错误
- 运行时错误C++程序:检测到glibc,munmap_chunk(),指针无效
- Linux中的c++运行时错误::glibc检测到free():无效的下一个大小(快速):堆栈具有void ptr元素
- 运行时错误:加载值 127,该值对于类型 'bool' 无效
- c++对象指针的优先级队列在运行时错误为无效堆