deconstructor issue

Im writing a program that is printing out binary search trees and binary trees.
Im getting a weird error involving the deconstructor of one of my ,h files.

F:\373\BSTree.h In destructor `BSTree<ItemType>::~BSTree() [with ItemType = int]':
9 F:\373\tree.cpp instantiated from here
9 F:\373\tree.cpp in lookup_member, at cp/search.c:1288

heres all the relevant code:
main:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "BTree.h"
#include "BSTree.h"
#include<stdlib.h>
#include<iostream>
using namespace std;
int main()
{
      BTree<int> BT;
      BSTree<int>BST;
      
      int x;
      int i;
      for(i=1;i<=5; i++)
      {
              x=rand()%100;
              BT.Insert(x);
              BST.Insert(x);
      }
      cout<<"Random Binary Tree: "<<endl;
      BT.InOrder(cout);
      cout<<endl;
      cout<<"Binary Search tree: "<<endl;
      BST.InOrder(cout);
      cout<<endl;
      
      x=46;
      cout<<"Search: "<<x<<endl;
      if(BST.Search(x))
      {
         cout<<"Found"<<endl;
      }
      else
      {
          cout<<"Not found"<<endl;
      }
      BST.PostOrder(cout);
      cout<<endl;
      BST.PreOrder(cout);
      cout<<endl;
      cout<<"Delete: "<<x<<endl;
      BST.Delete(x);
      BST.InOrder(cout);
      cout<<endl;
      BST.PreOrder(cout);
      cout<<endl;
      
      char quit;
      cin>>quit;
      return 0;
}


search tree header:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef BSTree_H
#define BSTree_H
#include "BTree.h"
#include "BTree.cpp"
#include<iostream>
using namespace std;
template <class ItemType>
class BSTree: public BTree<ItemType>
{
      private:
               typedef NodeType<ItemType> * TreePtr;
               TreePtr Tree;
               void R_Insert(TreePtr &, ItemType x, int=0, int=0);
               bool R_Search(TreePtr, ItemType);
               bool R_Delete(TreePtr &,ItemType);
   public:
    BSTree(){Tree = NULL;};
    virtual void Insert(ItemType x){R_Insert(Tree, x);};
    bool Search(ItemType x){ return R_Search(Tree, x);};
    bool Delete(ItemType x){ return R_Delete(Tree, x);};
    ~BSTree(){BTree<ItemType>::~BTree();};
};
#endif 


binary tree header:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef BTree_H
#define BTree_H

#include <fstream>
#include <stdlib.h>
//#include "queue.cpp"
//#incldue "Stack.cpp
#include "Node.cpp"
#include<iostream>
using namespace std;

template <class ItemType>
class BTree
{
      typedef NodeType<ItemType> * TreePtr;
      TreePtr Tree;
      void R_InOrder(TreePtr, ostream &);
      void R_PreOrder(TreePtr, ostream &);
      void R_PostOrder(TreePtr, ostream &);
      int R_Height(TreePtr);
      int R_Count(TreePtr);
      void R_Clear(TreePtr &);
      void R_Insert(TreePtr &, ItemType x, int=0, int=0);
   public:
    BTree(){Tree=NULL;};
      void InOrder(ostream &output){R_InOrder(Tree, output);};
      void PreOrder(ostream &output){R_PreOrder(Tree, output);};
      void PostOrder(ostream &output){R_PostOrder(Tree, output);};
      //void BFS(TreePtr,ostream &output);
      //void DFS(TreePtr,ostream &output);
      int Height(){return R_Height(Tree);};
      int Count(){return R_count(Tree);};
      virtual void Insert(ItemType x){R_Insert(Tree, x);};
      void Clear(){R_Clear(Tree);};
      ~BTree(){R_Clear(Tree);};

};
#endif 


clear function
1
2
3
4
5
6
7
8
9
10
11
template<class ItemType>
void BTree<ItemType>::R_Clear(TreePtr &t)
{
     if (t!=NULL)
     {
        R_Clear(t->Lt);
        R_Clear(t->Rt);
        delete t;
        t=NULL; 
     }
} 


any help is appreciated.
It looks like you didn't paste the whole error, can you repost the error message in full?

I don't see anything immediatley wrong... only thing I notice is that you're explicitly calling BTree's dtor from BSTree's dtor (which is not necessary/recommended)
that actually is the error.
o_O

But it doesn't say what the error is.

There's nothing else mentioned before or after that?
nope,but i think it has something to do with the destructors.
I'm having a really hard time believing you, but okay. What compiler is this, anyway?

Anyway the problem might not be in your destructor:

F:\373\tree.cpp in lookup_member, at cp/search.c:1288 


Can you whatever line that's referring to (line # 1288?) or even the whole function containing that line?
it refers to line 9 of the main function

BSTree<int>BST;
*scratches head*

That can't be right.... then why does it say 'lookup_member'?

I don't know. I can't really help with this one. The error doesn't tell me anything about the error and there's no way I can see for myself what's going on unless I can try to compile it, but this is too large to compile from a forum post.

Sorry.
I just looked over this, and I have to say, I am with Disch here. That doesn't look like any error I've ever seen, considering it lacks information about what the actual error is. :P I don't even see lookup_member in your code at all.
its alright,actually i just figured it out.it was in fact calling the bt destructor with the bst destructor,it was causing me grief. thanks for the help anyway though.
hay wait a minute... didn't I say that in my first reply?

haw
Topic archived. No new replies allowed.