473,416 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

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

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 Tclass 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 TTree<T>* Tree<T>::Left() const{
return left;
}

template <typename TTree<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 Tvoid 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 Tvoid 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!

Jan 1 '07 #1
1 2897
hn********@gmail.com wrote:
[full code -- thank you, by the way -- redacted]
Linker error on templated function.

This is a FAQ.

See http://www.parashift.com/c++-faq-lit...html#faq-35.13
Jan 1 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: pembed2003 | last post by:
Hi, I have a question about how to walk a binary tree. Suppose that I have this binary tree: 8 / \ 5 16 / \ / \ 3 7 9 22 / \ / \ / \
0
by: j | last post by:
Hi, Anyone out there with binary search tree experience. Working on a project due tomorrow and really stuck. We need a function that splits a binary tree into a bigger one and smaller one(for a...
2
by: dannielum | last post by:
Hi all, I am trying to write a Binary Search Tree that each of its node will have 3 node pointers: left, right and parent. I need a parent pointer for some the purpose of my project. Without the...
15
by: Foodbank | last post by:
Hi all, I'm trying to do a binary search and collect some stats from a text file in order to compare the processing times of this program (binary searching) versus an old program using linked...
10
by: free2cric | last post by:
Hi, I have a single link list which is sorted. structure of which is like typedef struct mylist { int num; struct mylist *next;
1
by: mathon | last post by:
hi, now i facing a problem which i do not know how to solve it...:( My binary search tree structures stores a double number in every node, whereby a higher number is appended as right child...
4
by: BenCoo | last post by:
Hello, In a Binary Search Tree I get the error : Object must be of type String if I run the form only with the "Dim bstLidnummer As New BinarySearchTree" it works fine. Thanks for any...
5
gekko3558
by: gekko3558 | last post by:
I am writing a simple binary search tree (nodes are int nodes) with a BSTNode class and a BST class. I have followed the instructions from my C++ book, and now I am trying to get a remove method...
11
by: Defected | last post by:
Hi, How i can create a Binary Search Tree with a class ? thanks
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.