Trouble Linking

Hello! I'm having a little problem with my program, which I believe may be due to a linking error. The error I receive when I try to compile is:
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl displayList(class Employee * &)" (?displayList@@YAXAAPAVEmployee@@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl deleteItem(class Employee * &)" (?deleteItem@@YAXAAPAVEmployee@@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl insertItem(class Employee * &)" (?insertItem@@YAXAAPAVEmployee@@@Z) referenced in function _main
1>C:\Documents\Visual Studio 2010\Projects\Project\Debug\Project.exe : fatal error LNK1120: 3 unresolved externals

Here is my code:
//main.cpp
#include "Employee.h"

using namespace std;

void insertItem(Employee *&head);
void deleteItem(Employee *&head);
void displayList(Employee *&head);

int main()
{
Employee *head = NULL;
char answer = 'Y';
int choice = 0;

do {
cout << "1.) Insert\n"
<< "2.) Delete\n"
<< "3.) Display List\n"
<< "4.) Exit\n";
cout << "Enter your choice: ";

cin >> choice;

switch (choice)
{
case 1: insertItem(head);
break;
case 2: deleteItem(head);
break;
case 3: displayList(head);
break;
case 4: exit(0);
default: cout << "\nInvalid Entry!\n\n";
break;
}
} while (choice != 4);
return 0;
}

//Employee.h
#include <iostream>
#include <string>
#ifndef EMPLOYEE_H
#define EMPLOYEE_H

using namespace std;

class Employee
{
private:
int _id;
string _name;
Employee *next;
public:
Employee();
~Employee();
void insertItem(Employee *& head);
void deleteItem(Employee *& head);
void displayList(Employee *& head);
};

#endif

//Employee.cpp
#include "Employee.h"

Employee::Employee()
{
_id = 0;
_name = "";
}

Employee::~Employee()
{
}

void Employee::insertItem(Employee *& head)
{
Employee * temp = new (Employee);
cout << "Enter ID: ";
cin >> temp->_id;
cin.ignore();
cout << "Enter Name: ";
getline(cin, temp->_name);
temp->next = head;
head = temp;
cout << endl;
}

void Employee::deleteItem(Employee *& head)
{
Employee *location;
Employee *place;
int idNum;
location = place = head;
cout << "\nEnter ID to delete: ";
cin >> idNum;
while ((location->_id != idNum)&&(location->next != NULL))
{
place = location;
location = location->next;
}
if ((location->_id == idNum)&&(location->next == NULL))
cout << "\nNot in the list.\n";
else if ((location->_id == idNum)&&(location->next == NULL))
{
place->next = NULL;
delete location;
}
else
{
place->next = location->next;
location->next = place;
delete location;
}
}

void Employee::displayList(Employee *&head)
{
Employee *temp = head;
cout << "\nHere is the list:\n";
while (temp != NULL)
{
cout << endl << "ID: " << temp->_id << endl;
cout << "NAME: " << temp->_name << endl;
temp = temp->next;
cout << endl;
}
}

Program should prompt the use to enter an employee id and name, delete an employee, or display the list of employees. Any help would be appreciated!
I haven't looked over all of the code so I am not sure if it's the only problem, but in your switch statement you are calling functions that are inside of the class, without listing the class they are inside.

You will probably want to change it to something like this
1
2
3
4
5
6
7
8
9
10
11
12

Employee *head = NULL;

switch (choice)
{
case 1: head->insertItem(head);
break;
case 2:  head->deleteItem(head);
break;
case 3:  head->displayList(head);
break;
Last edited on
Thank you! That fixed it. =]
Topic archived. No new replies allowed.