分割故障:GDB
Segmentation Fault: gdb
我是GDB的新手,一般来说,我不确定没有GDB,我不确定如何做到这一点。GDB告诉我的程序调试的程序是,此功能中存在分段故障。我将在下面的评论中强调它:
template <class elemType>
struct nodeType
{
elemType info;
nodeType<elemType> *lLink;
nodeType<elemType> *rLink;
};
#define H_binarySearchTree
#include <iostream>
#include "binaryTree.h"
using namespace std;
template <class elemType>
class bSearchTreeType: public binaryTreeType<elemType>
{
public:
bool search(const elemType& searchItem) const;
//Function to determine if searchItem is in the binary
//search tree.
//Postcondition: Returns true if searchItem is found in
// the binary search tree; otherwise,
// returns false.
void insert(const elemType& insertItem);
//Function to insert insertItem in the binary search tree.
//Postcondition: If there is no node in the binary search
// tree that has the same info as
// insertItem, a node with the info
// insertItem is created and inserted in the
// binary search tree.
void deleteNode(const elemType& deleteItem);
//Function to delete deleteItem from the binary search tree
//Postcondition: If a node with the same info as deleteItem
// is found, it is deleted from the binary
// search tree.
// If the binary tree is empty or deleteItem
// is not in the binary tree, an appropriate
// message is printed.
void printTree();
void printTree(nodeType<elemType> *p);
// void printTreeNode(nodeType<elemType> *p);
void swapSubtrees(nodeType<elemType> *root1);
void swapSubtrees();
nodeType<elemType> *root1;
template <class elemType>
void bSearchTreeType<elemType>::insert
(const elemType& insertItem)
{
nodeType<elemType> *current; //pointer to traverse the tree
nodeType<elemType> *trailCurrent; //pointer behind current
nodeType<elemType> *newNode; //pointer to create the node
newNode = new nodeType<elemType>;
newNode->info = insertItem;
newNode->lLink = NULL;
newNode->rLink = NULL;
if (root1 == NULL)
root1 = newNode;
else
{
current = root1;
while (current != NULL)
{
trailCurrent = current;
if (current->info == insertItem)//** This is where gdb says there is a seg fault
{
cout << "The item to be inserted is already ";
cout << "in the tree -- duplicates are not "
<< "allowed." << endl;
return;
}
else if (current->info > insertItem)
current = current->lLink;
else
current = current->rLink;
}//end while
if (trailCurrent->info > insertItem)
trailCurrent->lLink = newNode;
else
trailCurrent->rLink = newNode;
}
}//end insert
template<class elemType>
void bSearchTreeType<elemType>::swapSubtrees(nodeType<elemType> * root1)
{
if (root1 != NULL)
{
nodeType<elemType> *temp;
swapSubtrees(root1->lLink);//Seg Fault here as well
swapSubtrees(root1->rLink);
temp =root1->lLink;
root1->lLink = root1->rLink;
root1->rLink = temp;
}
}
}
有人可以帮助描述正在发生的事情,以及我需要做的修复?
*编辑以包括更多详细信息非常感谢
您忘了将root1
设置为构造函数中的NULL
- 实际上,您似乎没有一个。
相关文章:
- 分段故障(堆芯转储)矢量
- C++中的动态铸造故障
- 数组的指针从不分段故障
- 当在带有Eigen的C++中使用GDB时,我如何才能看到更多的大矩阵
- 如何找出GDB的SIGTRAP核心转储的根本原因
- vscode g++链路故障:体系结构x86_64的未定义符号
- 访问被拒绝后,c++中的故障保护代码
- Windows 10-使用gtkmm-3.0库和g++[包括再现]的分段故障
- 如何使用gdb制作一个可以漂亮地打印每个对象的C++函数
- gdb错误:Backtrace已停止:上一帧与此帧相同(堆栈已损坏?)
- 使用vscode调试时,GDB意外退出
- 调试 CUDA MMU 故障
- 多线程程序中的分段故障和gdb回溯上的不完整信息
- GDB执行时,Apache IGNITE C 客户端应用程序具有许多细分故障
- 远程 GDB 检查点/分叉故障
- 分割故障:GDB
- 分段故障11:GDB原因13
- 很奇怪的GDB分段故障分析
- 使用GDB调试时,分段故障消失
- 来自 ARM 皮层 M0 NRF51822 上的硬故障处理程序的 GDB 回溯