Why do I get LNK2019 error?

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//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');
}

Last edited on
Never mind figured it out
Last edited on
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.)
Last edited on
Topic archived. No new replies allowed.