I'm writing a program that uses a binary search tree. I'm trying to call on the binary search class in driver however, I get this error where I call BinarySearchTree<std::string> theTree.
//Driver.cpp
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <memory>
#include <ctime>
#include <vector>
#include "BinarySearchTree.h"
std::vector<std::string> theTreeSorted;
void display(std::string& anItem)
{
std::cout << anItem << " ";
theTreeSorted.push_back(anItem);
}
int main() {
// Declare variables
int userChoice = 0; // NUmber user choices from menu
std::string name; // name of person
std::string birthday; // person's birthday
std::string month; // month of person's birthday
// For file Birthdays.txt
std::ofstream foutput;
std::ifstream finput;
do {
BinarySearchTree<std::string> theTree; //Error occurs here
// Give user options on what they want to do with the list
std::cout << "1.Add a new person to list" << std::endl;
std::cout << "2.Modify a person's birthday" << std::endl;
std::cout << "3.Remove a person from the list" << std::endl;
std::cout << "4.Search for a person by name" << std::endl;
std::cout << "5.Search for a month(query)" << std::endl;
std::cout << "6.Print the entire list" << std::endl;
std::cout << "7.Quit" << std::endl;
std::cout << "Enter your choice: ";
std::cin >> userChoice;
switch (userChoice) {
// If type '1' then ask user to enter name and birthday
// then added what user types to list
case 1:
{
std::cout << "Enter name" << std::endl;
std::cin >> name;
std::cout << "Enter Birthday (Ex: Month, Day): ";
std::cin >> birthday;
// Open the Birthday.txt file
finput.open("Birthdays.txt");
foutput.open("Birthdays.txt", std::ios::app);
// If file is open add name and birthday entered to file
if (finput.is_open()) {
foutput <<"Name: " << name << " "; // add name
foutput <<"Birthday: " << birthday << std::endl; // add birthday
}
// Close file
finput.close();
foutput.close();
}
break;
// If user types '2' then ask user for person's name and new birthday
// Then delete previous birthday and add new birthday
case 2:
{
std::cout << "Enter name of the person you would like to modify" << std::endl;
std::cin >> name;
std::cout << "Enter the new person's birthday" << std::endl;
std::cin >> birthday;
// Open the Birthday.txt file
finput.open("Birthdays.txt");
foutput.open("Birthdays.txt", std::ios::app);
// If file is open add name and birthday entered to file
if (finput.is_open()) {
foutput << "Name: " << name << " "; // add name
foutput << "Birthday: " << birthday << std::endl; // add birthday
}
// Close file
finput.close();
foutput.close();
}
break;
// If the user selects '3' then remove person from list
case 3:
{
std::cout << "Enter the name of the person you want to remove" << std::endl;
std::cin >> name;
// Open the Birthday.txt file
finput.open("Birthdays.txt");
foutput.open("Birthdays.txt", std::ios::app);
}
break;
// If user type '4' then search for person name user entered
// then print the birthday of that person
case 4:
{
std::cout << "Enter the name of the person you want to search for" << std::endl;
std::cin >> name;
}
break;
// If user types '5' then search for who's birthdays are in month entered by user
case 5:
{
std::cout << "Enter the month you want to search for" << std::endl;
std::cin >> month;
}
break;
// If user types '6' then print the entire list
case 6:
{
//people.printInOrder();
}
break;
// If user types '7' then exit program
case 7:
{
exit(1);
}
break;
}
}
// While the user choice is not to quit
while (userChoice != '7');
}
In the future don't just give the code number of the error.
Instead, state what the error actually is.
In this case it is "unresolved external symbol 'symbol' referenced in function 'function'".
(Where 'symbol' and 'function' will of course be your identifiers.)