Link Error, Why doesn't my simple binary search tree class work??

H

hn.ft.pris

I have the following code:

Tree.h defines a simple binary search tree node structure
########## FILE Tree.h ################
#ifndef TREE_H
#define TREE_H
//using namespace std;
template <typename T> class Tree{
private:
Tree<T> *left;
Tree<T> *right;
T data;
public:
Tree(const T& item, Tree<T>* lptr, Tree<T>*
rptr):data(item),left(lptr),right(rptr){};
Tree<T>* Left() const;
Tree<T>* Right() const;
};

#endif
#######################################


Tree.cpp implemented Tree<T>* Left() const and Tree<T>* Right() const
###############FILE Tree.cpp ###########
#include "Tree.h"
#include <iostream>
using namespace std;

template <typename T> Tree<T>* Tree<T>::Left() const{
return left;
}

template <typename T> Tree<T>* Tree<T>::Right() const{
return right;
}
########################################

Tree_Scan.h defines a "inorder" scan function on the binary search tree
################## FILE Tree_Scan.h#########
#ifndef TREE_SCAN_H
#define TREE_SCAN_H

#include "Tree.h"
//using namespace std;

template <typename T> void inorder(Tree<T>*);

#endif
###########################################

Tree_Scan.cpp implemented "inorder" function
#################FILE Tree_Scan.cpp#########
#include "Tree.h"
#include "Tree_Scan.h"
#include <iostream>
using namespace std;

template <typename T> void inorder(Tree<T>* tree){
if(tree != NULL){

inorder(tree->left());

cout << (*tree).data << endl;

inorder(tree ->right());
}
}
###########################################

In the main function, first a binary search tree is built and then
perform an "inorder" scan
on it
##################FILE main.cpp#############
#include "Tree.h"
#include "Tree_Scan.h"
#include <string>
using namespace std;

int main(){
Tree<string> *g = new Tree<string>("G", NULL, NULL);
Tree<string> *h = new Tree<string>("H", NULL, NULL);
Tree<string> *i = new Tree<string>("I", NULL, NULL);
Tree<string> *f = new Tree<string>("F", NULL, NULL);

Tree<string> *d = new Tree<string>("D", NULL, g);
Tree<string> *b = new Tree<string>("B", d, NULL);
Tree<string> *e = new Tree<string>("E", h, i);
Tree<string> *c = new Tree<string>("C", e, f);
Tree<string> *a = new Tree<string>("A", b, c);

inorder(a);

return 1;
}
##################################################

When linking a got a link error, complain that there is something wrong
with "inorder(a)", I've
checked my program several times and find no problem, why it fails?
Thanks for helping me!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top