1

I am at a bit of a loss for what the error is pointing to. It says the error is on line 1, it says the error is in a non-existant file, the error changes when I initialize employeeId().

I searched through the StackOverflow database about externals, about the specific output I am seeing, but there have been no questions specific to the output or the external symbols.

If anyone can explain why I am seeing this output, I would appreciate it.

The output from the build:

Build started...

1>------ Build started: Project: Employee salary calculator, Configuration: Debug x64 ------
1>Source.cpp
1>Source.obj : error LNK2001: unresolved external symbol "private: static int Employee::count" (?count@Employee@@0HA)
1>Source.obj : error LNK2001: unresolved external symbol "private: static int Employee::employeeId" (?employeeId@Employee@@0HA)
1>C:\Users\ipyra\OneDrive\Documents\edx hands-on projects\Employee salary calculator\x64\Debug\Employee salary calculator.exe : fatal error LNK1120: 2 unresolved externals
1>Done building project "Employee salary calculator.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Both error codes are for unresolved external symbols, and reference both Employee::count and Employee::employeeId. It also references source.obj, and I do not know what that file is, nor do I see it in my project. This is supposed to be a single file solution for homework. Any help would be appreciated.

#include <iostream>
#include <string.h>
using namespace std;
class Employee
{
private:
    // Changed employeeId and count from non-static to static, per stack-exchange information
    static int count;
    static int employeeId;
    string employeeName;
    double salary;
    double netSalary;
public:
    void setEmployeeId(int id)
    {
        employeeId = id;
    }
    static int getEmployeeId()
    {
        return employeeId;
    }
    void setEmployeeName(string name)
    {
        this->employeeName = name;
    }
    string getEmployeeName()
    {
        return this->employeeName;
    }
    void setSalary(double sal)
    {
        this->salary = sal;
    }
    double getSalary()
    {
        return this->salary;
    }
    void setNetSalary(double netSal)
    {
        this->netSalary = netSal;
    }
    double getNetSalary()
    {
        return this->netSalary;
    }
    void calculateNetSalary(int pfpercentage)
    {
        double grossSal, calcNetSal;
        grossSal = getSalary();
        calcNetSal = grossSal - grossSal * pfpercentage / 100;
        setNetSalary(calcNetSal);
    };

    // This outputs employee details
    void display()
    {
        cout << out1 << getEmployeeId();
        cout << out2 << getEmployeeName();
        cout << out3 << getNetSalary();
    };
    void getEmployeeDetails();
    
    
    //fill the code here
    // These are strings used in prompts and outputs
    string prompt1 = "Enter Name:", prompt2 = "Enter salary (In dollars):", prompt3 = "Enter PF percentage:",empName;
    string out1 = "Id: ", out2 = "Name: ", out3 = "Net salary (In dolars): ";

    // These are used by functions
    int pfPercentage;
    double empSalary;

    // This series of commands prompts user inputs, and accepts user inputs
    void promptGet1()
    {
        cout << prompt1 << endl;
    }
    void get1()
    {
        cin >> empName;
    }
    void promptGet2()
    {
        cout << prompt2 << endl;
    }
    void get2()
    {
        cin >> empSalary;
    }
    void promptGet3()
    {
        cout << prompt3 << endl;
    }
    void get3()
    {
        cin >> pfPercentage;
    }

    // This command executes a series of commands, setting values
    void setEmployeeDetails()
    {
        setEmployeeName(empName);
        setSalary(empSalary);
        calculateNetSalary(pfPercentage);
        setEmployeeId(100);
        setCountId(0);
        generateEmployeeId();
    }
    static void setCount(int count)
    {
    count = count;
    }
    static int getCount()
    {
        return count;
    }
    static void setCountId(int count)
    {
        count = count;
    }

    // This counter creates the employee ID number
    static int generateEmployeeId()
    {
        int empId{ 100 };
        int countId{ 0 };

        countId = getCount();
        countId++;
        setCount(countId);

        empId = getEmployeeId();

        return empId + countId;
    }


    

};

int main() //DO NOT change the 'main' signature
{
    //create object for Employee class
    Employee emp;
    //fill the code here
    emp.promptGet1();
    emp.get1();
    emp.promptGet2();
    emp.get2();
    emp.promptGet3();
    emp.get3();
    emp.setEmployeeDetails();
    emp.display();

    

    return 0;
}

0 Answers0