Have a simple error. Looked at a bunch of posts and checked the causes on my files, but couldn't seem to fix it. The functions being called from my BST.cpp file are throwing the error in the title ("identifier "buildTree" is undefined). The functions in question are 'buildTree' and 'performSearchBST'. The CPP file is included in main and the class templates are declared on all of the functions. Probably a simple error but was hoping someone could help point it out for me. Code listed below. As always thank you in advance for your assistance.
Main File:
//..
#include "BST.cpp"
#include "Node.h"
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main()
{
//...
ifstream filename("grocery_upc_database.csv");
BST<UPC> tree = buildTree(filename); //build binary search tree of UPC objects
string code;
cout << "Please enter a UPC code(! to quit): ";
cin >> code;
while (code != "!")
{
long entry = stol(code); //convert user inputted string to type long int
UPC key(entry);
performSearchBST(tree, key);
cout << "\nPlease enter a UPC code(! to quit): ";
cin >> code;
}
return 0;
}
BST.cpp
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <fstream>
#include "BST.h"
using namespace std;
template <class T>
BST<T>::BST()
{
root = NULL;
}
template <class T>
BST<T>::BST(long upcdata, string descrip)
{
root->data = upcdata;
root->descrip = descrip;
}
template <class T>
void BST<T>::buildTree(string inFile)
{
string upcholder;
string description;
string line;
ifstream file;
file.open("grocery_upc_database.csv");
while (getline(file, line))
{
stringstream ss(line);
getline(ss, upcholder, ',');
getline(ss, description, '\t');
Node<T> newNode;
newNode->data = stol(upcholder);
newNode->descrip == description;
insert(newNode);
}
}
template <class T>
void BST<T>::insert(Node<T> *newNode)
{
insert2(root, newNode);
}
template <class T>
void insert2(Node<T> *&root, Node<T> *newNode)
{
if (root->data = NULL)
{
root = newNode;
}
else if (newNode->data < root->data)
{
insert2(root->left, newNode);
}
else
{
insert(root->right, newNode);
}
}
template <class T>
long BST<T>::stol(string item)
{
long i = atol(item.c_str());
return i;
}
template <class T>
bool BST<T>::performSearchBST(BST<T> bst, UPC key)
{
return performSearchBST2(bst,key);
}
template <class T>
bool performSearchBST2(BST<T> bst, UPC key)
{
if (bst.root == NULL)
return false;
if (bst.root->data == key)
return true;
else if (root->data < key)
return performSearchBST2(root->right, key);
else
return performSearchBST2(root->left, key);
}
BST.h
#include <iostream>
#include <string>
#include "Node.h"
using namespace std;
template <class T>
class BST
{
Node<T> *root;
public:
BST();
BST(long key, string descrip);
bool find(T item);
bool performSearchBST(BST<T> bst, UPC key);
void buildTree(string inFile);
void insert(Node<T>* newNode);
long stol(string item);
};