Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8808779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:42:26+00:00 2026-06-14T02:42:26+00:00

I have a linker error and I don’t seem to figure out: The default

  • 0

I have a linker error and I don’t seem to figure out:

The default constructor sets name to “Unknown”, Office Number to nextOfficeNo, Employee number to the value of nextEmpId, Department number to 0, Employee Position to Entry level, year of experience to 0, and salary to 0. It also ensures that the values of all static attributes are incremented by 1.

The second constructor sets the attributes based on what is passed to the function. The value of Employee Salary would still be set to 0 and the values of Office Number and Employee number are set to nextOfficeNo and nextEmpId, respectively. Again, the constructor should increment the values of all static attributes by 1.
also; The value of totalNumOfEmployees must be initialized to 0 before creating any object, be incremented upon creating each object of class Employee (in every constructor), and be decremented when an object of class Employee goes out of scope (in destructor).

The value of nextEmpId must be initialized to 1000 before creating any object, and must be incremented upon creating each object of class Employee in every constructor.

The value of nextOfficeNo must be initialized to 10 before creating any object, and must be incremented upon creating each object of class Employee in every constructor.

this is my header class:

#include <iostream>
#include <string>
using namespace std;

class Employee
{
private:
    string name;
    const long officeNo;
    const long empId;
    int deptNo;
    char empPosition; // ‘E’: entry level, ‘M’: manager, ‘D’: Director, ‘P’:Project_leader
    int yearOfExp;
    float salary;
    static int totalNumofEmployees;
    static int nextEmpId;
    static int nextOfficeNo;
public:
    Employee();
    ~Employee();
    Employee(string theName, int theDeptNo, char theEmpPosition, int theYearOfExp);
    void Print() const ;
    void GetInfo();
    friend void setSalary(Employee& );
 };

and this is my CPP class:
I have the problems in my constructors:

#include "Employee.h"
#include <string>
#include <iostream>

Employee::Employee()
  : officeNo(nextOfficeNo), empId(nextEmpId)
{
    name = "Unknown";
    deptNo = 0;
    empPosition = 'E';
    yearOfExp = 0;
    salary = 0;
    totalNumofEmployees = 0;
    nextEmpId = 1000;
    nextOfficeNo = 10;
    totalNumofEmployees++;
    nextEmpId++;
    nextOfficeNo++;
}

Employee::Employee(string theName, int theDeptNo, char theEmpPosition, int theYearOfExp)
  : officeNo(nextOfficeNo), empId(nextEmpId)
{
    name = theName;
    deptNo = theDeptNo;
    empPosition = theEmpPosition;
    yearOfExp = theYearOfExp;
    salary = 0;
    totalNumofEmployees = 0;
    nextEmpId = 1000;
    nextOfficeNo = 10;
    totalNumofEmployees++;
    nextEmpId++;
    nextOfficeNo++;
}

here are the errors:

{Undefined symbols for architecture x86_64:
"Employee::nextOfficeNo", referenced from:
Employee::Employee() in Employee.o
Employee::Employee(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int, char, int) in Employee.o
"Employee::totalNumofEmployees", referenced from:
Employee::Employee() in Employee.o
Employee::Employee(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int, char, int) in Employee.o
Employee::~Employee() in Employee.o
Employee::Print() const in Employee.o
"Employee::nextEmpId", referenced from:
Employee::Employee() in Employee.o
Employee::Employee(std::__1::basic_string<char, std::__1::char_traits<char>,  std::__1::allocator<char> >, int, char, int) in Employee.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:42:27+00:00Added an answer on June 14, 2026 at 2:42 am

    You have declared static member variables but you forgot to define them:

    § 9.4.2/2 The declaration of a static data member in its class definition is not a definition and may be of an
    incomplete type other than cv-qualified void. The definition for a static data member shall appear in a
    namespace scope enclosing the member’s class definition. In the definition at namespace scope, the name
    of the static data member shall be qualified by its class name using the :: operator. The initializer
    expression in the definition of a static data member is in the scope of its class.

    // Example:
    class process {
        static process* run_chain;
        static process* running;
    };
    process* process::running = get_main();
    process* process::run_chain = running;
    

    In your case:

    // add this to your .cpp
    int Employee::totalNumofEmployees = 0;
    int Employee::nextEmpId = 1000;
    int Employee::nextOfficeNo = 10;
    

    And remove these assignments from your constructors:

    totalNumofEmployees = 0;
    nextEmpId = 1000;
    nextOfficeNo = 10;
    

    Otherwise, ever time you create an object, these values are reset.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a link error where the linker complains that my concrete class's destructor
EDIT : I seem to have solved the problem, even if I don't know
C++ projects have a linker option to embed manifest to require UAC elevation (/MANIFESTUAC:level)
I am using codeblocks as my IDE. I have all the linker settings perfect,
I am using Scons to build my C project. I have an external linker
I have the same error than here . There's no solution there and also
I'm getting this linker error. I know a way around it, but it's bugging
Apologize because for the moment I don't have the environment to experiment and sort
I'm getting this linker error when compiling wxWidgets in Visual Studio 2010. msvcrt.lib(wcrtexew.obj) :
After having some problems with these two linker errors on SO , I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.