C++ 二叉搜索树<&书信电报;操作员过载不工作

C++ 二叉搜索树<&书信电报;操作员过载不工作,c++,class,linked-list,operator-overloading,binary-search-tree,C++,Class,Linked List,Operator Overloading,Binary Search Tree,我有3个类创建了一个完整的二叉搜索树。这三个班是 1.DBentry(存储名称、IP地址和状态), 2.TreeNode(指向其自己的DBentry,以及其左侧和右侧的条目) 3.TreeDB(包含根TreeNode,并提供各种函数来添加、删除、更新和查找DBentryobjects) 在DBentry中,我有朋友ostream&operatorostream&operator,即使返回;它给出了一个分段错误。@Fabiabushratamana如果条目不为空,左或右是否可能为空?打印NULL是

我有3个类创建了一个完整的二叉搜索树。这三个班是 1.DBentry(存储名称、IP地址和状态), 2.TreeNode(指向其自己的DBentry,以及其左侧和右侧的条目) 3.TreeDB(包含根TreeNode,并提供各种函数来添加、删除、更新和查找DBentryobjects)


在DBentry中,我有
朋友ostream&operator
ostream&operator,即使返回;它给出了一个分段错误。@Fabiabushratamana如果条目不为空,左或右是否可能为空?打印NULL是一种容易崩溃的方法。是的,左边或右边都可以是NULL。我怎样才能解决这个问题?
class DBentry {
private:
string name;
unsigned int IPaddress;
    bool active;

public:

DBentry();
    DBentry (string _name, unsigned int _IPaddress, bool _active);


~DBentry(); 


void setName(string _name);


void setIPaddress(unsigned int _IPaddress);


    void setActive (bool _active);


string getName() const;


unsigned int getIPaddress() const;


    bool getActive() const;

    friend ostream& operator <<(ostream& out, const DBentry& rhs);
};
class TreeNode {
private:
DBentry* entryPtr;
TreeNode* left;
TreeNode* right;

public:
TreeNode();

TreeNode(DBentry* _entryPtr);


~TreeNode();


void setLeft(TreeNode* newLeft);


void setRight(TreeNode* newRight);


TreeNode* getLeft();


TreeNode* getRight();


DBentry* getEntry() const;

bool find(string _name);


};
ostream& operator <<(ostream& out, const DBentry& rhs){
out<<rhs.name<<" : "<<rhs.IPaddress<<" : ";//<<rhs.active?    (out<<"active"):(out<<"inactive")<<endl;
if(rhs.active)
    out<<"active";
else
    out<<"inactive";
out<<endl;
}

ostream& operator <<(ostream& out, TreeNode& rhs){
if(rhs.getEntry()!=NULL){
    out << *(rhs.getLeft());
    out << *(rhs.getEntry());
    out << *(rhs.getRight());
}
}

ostream& operator<< (ostream& out, const TreeDB& rhs){
out << *(rhs.root);
}
ostream& operator <<(ostream& out, TreeNode& rhs){
    if(rhs.getEntry()!=NULL){
        out << *(rhs.getLeft());
        out << *(rhs.getEntry());
        out << *(rhs.getRight());
    }
    return out; //<-- return the stream. Do not cross streams unless fighting Gozer.
}