I have a Binary Search Tree as a derived class from a Binary Tree, right now I am trying to access the root for my recursive functions (which is in the base class). But for some reason I keep getting the error:
binSTree.h:31: error: ‘root’ was not declared in this scope
Here are my class declarations:
base class:
template <class T>
class binTree {
private:
int height(treeNode<T>*) const; // Recursive method
int size(treeNode<T>*) const; // Recursive method
int leaves(treeNode<T>*) const;
void insert(treeNode<T>*&, const T&);
void clear(treeNode<T>*);
treeNode<T>* copy_tree(treeNode<T>*);
void preOrder(treeNode<T>*, void (*)(T&));
void inOrder(treeNode<T>*, void (*)(T&));
void postOrder(treeNode<T>*, void (*)(T&));
public:
binTree();
binTree(const binTree<T>&);
~binTree();
bool empty() const;
void clear();
void insert(const T&);
int remove(const T&); // Extra credit only
int height() const; // Non-recursive method
int size() const; // Non-recursive method
int leaves() const;
void preOrder(void (*)(T&));
void inOrder(void (*)(T&));
void postOrder(void (*)(T&));
const binTree<T>& operator=(const binTree<T>&);
protected:
treeNode<T>* root;
};
header file (to line 31):
#include "binTree.h"
template<class T>
class binSTree : public binTree<T> {
public:
void insert(const T&);
bool remove(const T&);
bool search(const T&, int&) const;
private:
void insert(treeNode<T>*&, const T&);
bool remove(treeNode<T>*&, const T&);
bool search(treeNode<T>*, const T&, int&);
void remove_root(treeNode<T>*&);
};
template<class T>
void binSTree<T>::insert(const T& x) {
treeNode<T>* newNode = new treeNode<T>(x);
insert(newNode, x);
}
template<class T> // public
bool binSTree<T>::remove(const T& x) {
return remove(binTree<T>.root, x);
}
template<class T> // public
bool binSTree<T>::search(const T& x, int& len) const {
len = 0;
len = search(root,x,len);
}
I tried making the root public to see what would happen, and I still got the same error.
any help would be much appreciated!