What is this error?

Error 1 error LNK2019: unresolved external symbol "public: __thiscall Employee::Employee(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,double)" (??0Employee@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@N@Z) referenced in function _main F:\Users\Boss\Documents\Visual Studio 2012\Projects\Employee\Employee\employee.obj Employee

Error 2 error LNK2019: unresolved external symbol "public: void __thiscall Employee::set_salary(double)" (?set_salary@Employee@@QAEXN@Z) referenced in function _main F:\Users\Boss\Documents\Visual Studio 2012\Projects\Employee\Employee\employee.obj Employee
Error 3 error LNK2019: unresolved external symbol "public: double __thiscall Employee::get_salary(void)const " (?get_salary@Employee@@QBENXZ) referenced in function _main F:\Users\Boss\Documents\Visual Studio 2012\Projects\Employee\Employee\employee.obj Employee
Error 4 error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Employee::get_name(void)const " (?get_name@Employee@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function _main F:\Users\Boss\Documents\Visual Studio 2012\Error 5 error LNK1120: 4 unresolved externals F:\Users\Boss\Documents\Visual Studio 2012\Projects\Employee\Debug\Employee.exe EmployeeProjects\Employee\Employee\employee.obj Employee

...It would help to see the associated code.
Looks like you're making a call to a function that you have declared, but you never defined it anywhere.
Thanks guys for your responses. Here is the associated code. I included the header file that is giving the problem. Whenever I run it, I get the LNK 2019 error. I tried copying the header file to my VC 'include' directory but get the same error.


#ifndef CCC_EMPL_H
#define CCC_EMPL_H

#include <string>

using namespace std;

/**
A basic employee class that is used in many examples
in the book "Computing Concepts with C++ Essentials"
*/
class Employee
{
public:
/**
Constructs an employee with empty name and no salary.
*/
Employee();
/**
Constructs an employee with a given name and salary.
@param employee_name the employee name
@param initial_salary the initial salary
*/
Employee(string employee_name, double initial_salary);
/**
Sets the salary of this employee.
@param new_salary the new salary value
*/
void set_salary(double new_salary);
/**
Gets the salary of this employee.
@return the current salary
*/
double get_salary() const;
/**
Gets the name of this employee.
@return the employee name
*/
string get_name() const;
private:
string name;
double salary;
};

#endif

#include <iostream>

using namespace std;

#include "ccc_empl.h"

int main()
{
Employee harry("Hacker, Harry", 45000.00);

double new_salary = harry.get_salary() + 3000;
harry.set_salary(new_salary);

cout << "Name: " << harry.get_name() << "\n";
cout << "Salary: " << harry.get_salary() << "\n";

return 0;
}

closed account (3qX21hU5)
Yup you are declaring your class's member functions, but you never define them. Remember with member functions usually they will be defined in a seperate file. Here is a short simple example.


MyClass.h
1
2
3
4
5
6
7
8
9
10
//Class declaration usually go into their own header file.

class MyClass
{
    public:
        void addToNumber(int addNumber);    // This is a declaration

    private:
        int number;
}


MyClass.cpp

1
2
3
4
5
6
7
8
// All the member function definitions will usually go into a seperate .cpp file.

#include "MyClass.h"

void MyClass::addToNumber(int addNumber)  // This is a definition
{
    number += addNumber;
}


Now that is just a short example of it and yours will be much more complex probably but it shows the general idea. Basically you have the class declaration but you forgot to write the definition which tells what each member function in your class is suppose to do.

Hope this helps a bit if you have any other questions or don't get anything just let me or someone know and we will try and help you as best we can.
Last edited on
That was it. The member functions was not define. Thanks guys for your help.
Topic archived. No new replies allowed.