#ifndef BINARYTREE_H
#define BINARYTREE_H
#include <iomanip>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
class binarytree
{
private:
struct tree
{
int val;
tree *left;
tree *right;
};
tree *root;
void insert(tree *&, tree *&);
void display(tree *) const;
void destroy(tree *);
public:
binarytree()
{root = NULL;}
~binarytree()
{destroy(root);}
void insertnode(int);
bool search(int);
void display() const
{ display(root); }
};
#endif // BINARYTREE_H
これは私の.hです
これは私の.cppです
#include "binarytree.h" // class's header file
#include <iomanip>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
void binarytree :: insertnode( int num)
{
tree *newnode;
newnode = new tree;
newnode->val = num;
newnode->left = newnode->right = NULL;
insert(root, newnode);
}
void binarytree :: insert(tree *&Ptr, tree *&newnode)
{
if(Ptr == NULL)
Ptr = newnode;
else if( newnode->val < Ptr->val)
insert(Ptr->left, newnode);
else
insert(Ptr->right, newnode);
}
void binarytree :: destroy(tree *Ptr)
{
if(Ptr)
{
if(Ptr->left)
destroy(Ptr->left);
if(Ptr->right)
destroy(Ptr->right);
delete Ptr;
}
}
これはデストラクタエラーだと思いますが、理由がわかりません。構文エラーか何かがある場合、私は非常にばかげているように感じますが、これは本からコピーしたばかりなので、何かが欠けているようには見えません. どんなアドバイスも役に立ちます。説明が必要な場合は、お尋ねください。