Hello,
I am trying to test my binary tree, but I am getting errors: The error occurs when I try to call a template function. For example: tree.insertNode(inp);. I get this error: request for member âinsertNodeâ in âtreeâ, which is of non-class type âmain()::binaryTree ()()â
.
I have defined my template and called the constructor in my program:
typedef BinaryTree<int> binaryTree;
binaryTree tree();
I have linked my binaryTree.hpp, binaryTree.cpp and testPro.cpp in a make file and included #include "binaryTree.hpp" in testPro.cpp. testPro.cpp is where I am testing the tree and getting the errors.
Here is the binaryTree.hpp file:
#ifndef BINARYTREE_H
#define BINARYTREE_H
#include <iostream>
using namespace std;
template <class T>
class BinaryTree
{
public:
struct TreeNode
{
T value;
TreeNode *left;
TreeNode *right;
};
int leafCount;
TreeNode *root;
void insert(TreeNode *&, TreeNode *&);
void destroySubTree(TreeNode *);
void deleteNode(T, TreeNode *&);
void makeDeletion(TreeNode *&);
void displayInOrder(TreeNode *);
void displayPreOrder(TreeNode *);
void displayPostOrder(TreeNode *);
int countNodes(TreeNode *&);
void countLeaves(TreeNode *);
int getTreeHeight(TreeNode *);
int numAtLevel(TreeNode *, int);
public:
BinaryTree() // Constructor
{ root = NULL; }
~BinaryTree() // Destructor
{ destroySubTree(root); }
void insertNode(T);
// searchNode has been modified.
T *searchNode(T);
void remove(T);
void displayInOrder()
{ displayInOrder(root); }
void displayPreOrder()
{ displayPreOrder(root); }
void displayPostOrder()
{ displayPostOrder(root); }
int numNodes();
int numLeafNodes();
int treeHeight();
int getWidth();
};
#endif
Thank you in advance!