473,226 Members | 1,531 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,226 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 2886
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
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.