C++ 链接器错误2001未解析的外部符号

C++ 链接器错误2001未解析的外部符号,c++,vector,stl,linker,linker-errors,C++,Vector,Stl,Linker,Linker Errors,我以前从来没有犯过这样的错误,请记住我还在学校,所以我做这件事的时间不长 我得到的错误是: 错误1错误LNK2001:未解析的外部符号“private:static class std::vector>Job::names”(?names@Job@@0V$vector@PBDV?$allocator@PBD@std@@@std@@A)Job.obj工资计算器 错误2错误LNK2001:未解析的外部符号“private:static class std::vector>Job::percentBa

我以前从来没有犯过这样的错误,请记住我还在学校,所以我做这件事的时间不长

我得到的错误是:

错误1错误LNK2001:未解析的外部符号“private:static class std::vector>Job::names”(?names@Job@@0V$vector@PBDV?$allocator@PBD@std@@@std@@A)Job.obj工资计算器

错误2错误LNK2001:未解析的外部符号“private:static class std::vector>Job::percentBased”(?percentBased@Job@@0V$vector@_NV?$allocator@_N@std@@@std@@A)Job.obj工资计算器

错误3错误LNK2001:未解析的外部符号“private:static class std::vector>Job::pay”(?pay@Job@@0V$vector@MV?$allocator@M@std@@@std@@A)Job.obj工资计算器

我不知道从哪里开始这样的错误,所以如果有人可以帮助。 以下是相关代码(如果有帮助):

stdafx.h:

#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <string>
#include <iostream>
#include <limits>
#include <vector>
#包括“targetver.h”
#包括
#包括
#包括
#包括
#包括
#包括
Job.h:

#include "stdafx.h"
class Job
{
public:
    Job();
    Job(const char*);

    const char* getName();
    float getPay();
private:
    static std::vector<const char*> names;
    static std::vector<bool> percentBased;
    static std::vector<float> pay;
    short jobType = -1;

    void defineNew(const char*);
    void setPay();
};
#包括“stdafx.h”
班级作业
{
公众:
Job();
工作(常数字符*);
const char*getName();
浮动工资();
私人:
静态std::向量名;
静态std::基于向量的百分比;
静态标准::向量支付;
短作业类型=-1;
void defineNew(常量字符*);
无效设置支付();
};
Job.cpp

#include "stdafx.h"
#include "Job.h"

Job::Job()
{
    // Predefined jobs
    const char* jobs[] = {/*Enter names of jobs here*/ "agent", "lawyer", "pa", "trainer" };
    bool percentPays[] = {/*Enter weather jobs base pay off a percentage of the employers income here*/ true, true, true, true };
    float pays[] = {/*Enter the percentage or base pay for each job here*/ (float).07, (float).1, (float).03, (float).05 };

    // Initilize Vectors
    names.assign(jobs, jobs + sizeof(jobs));
    percentBased.assign(percentPays, percentPays + sizeof(percentPays));
    pay.assign(pays, pays + sizeof(pays));
}

Job::Job(const char* jobName)
{
    // Test to see if the inputed job type is alrady defined
    for (unsigned int i = 0; i <= names.size(); i++)
    {
        if (jobName == names[i])
        {
            jobType = i;
            break;
        }
    }

    // Define new job
    if (jobType < 0)
    {
        defineNew(jobName);
        jobType = names.size() + 1;
    }
}

void Job::defineNew(const char* newName)
{
    // Add job to list of jobs
    names.push_back(newName);

    // Determine if job pay is based of percentage of employers income
    std::cout << "The entered job title is not predefined.\n"
              << "Dose the job " << newName << " have a pay based on a percentage of the employer's Income? [y/n] ";
    for (;;)
    {
        // Get input
        std::string input;
        std::getline(std::cin, input);
        // Convert input into useable data
        for (std::string::iterator it = input.begin(); it != input.end(); it++)
        {
            if (isalpha(*it) && isupper(*it)) *it = tolower(*it);
        }

        // Test input if yes job is percent based pay other wise no
        if (input == "yes" || input == "y")
        {
            percentBased.push_back(true);
            break;
        }
        else if (input == "no" || input == "n")
        {
            percentBased.push_back(false);
            break;
        }
        else
        {
            std::cout << "Invalid Input! Enter only yes or no.\n"
                      << "Dose the job " << newName << " have a pay based on a percentage of the employer's income? [y/n] ";
        }
    }

    setPay();
}

void Job::setPay()
{
    // Set new pay
    if (percentBased.back())
    {
        std::cout << "Enter the percentage of the employer's income the pay is based on: ";
    }
    else
    {
        std::cout << "Enter the jobs base pay: ";
    }

    for (;;)
    {
        // Get input
        std::string input;
        std::getline(std::cin, input);
        // Convert input to useable data
        bool goodInput = true, decimal = false;
        for (std::string::iterator it = input.begin(); it != input.end(); it++)
        {
            if (ispunct(*it) && !decimal)
            {
                decimal = true;
            }
            else if (!isalnum(*it))
            {
                goodInput = false;
            }
            else
            {
                std::cout << "Invalid Input! Input only numbers.\n"
                          << "Enter a number greater than 0: ";
            }
        }

        // Add pay information if good
        float tempPay = std::stof(input);
        if (goodInput && percentBased.back() && (tempPay >= 0 && tempPay < 1))
        {
            pay.push_back(tempPay);
            break;
        }
        else if (goodInput && percentBased.back() && !(tempPay >= 0 && tempPay < 1))
       {
            std::cout << "Invalid Input! Input only numbers between 0 and 1.\n"
                      << "Enter percentage greater than 0 and less than 1: ";
        }
        else if (goodInput && !percentBased.back() && tempPay >= 0)
        {
            pay.push_back(tempPay);
            break;
        }
        else if (goodInput && !percentBased.back() && tempPay < 0)
        {
            std::cout << "Invalid Imput! Input only numbers greater than 0.\n"
                      << "Enter a base pay greater than 0: ";
        }
    }
}

const char* Job::getName()
{
    return names[jobType];
}

float Job::getPay()
{
    return pay[jobType];
}
#包括“stdafx.h”
#包括“Job.h”
作业::作业()
{
//预定义作业
const char*jobs[]={/*在此处输入职务名称*/“代理人”、“律师”、“私人助理”、“培训师”};
bool percentPays[]={/*在此处输入天气工作基本工资占雇主收入的百分比*/真,真,真,真};
浮动工资[]={/*在此处输入每个工作的百分比或基本工资*/(浮动).07,(浮动).1,(浮动).03,(浮动).05};
//初始化向量
名称。分配(作业,作业+大小(作业));
基于百分比的分配(百分比支付,百分比支付+大小(百分比支付));
支付。分配(支付,支付+sizeof(支付));
}
作业::作业(常量字符*作业名称)
{
//测试以查看输入的作业类型是否已定义

对于(unsigned int i=0;i您仅在Job.h文件中声明了
名称、基于百分比的薪酬
,您需要在Job.cpp中定义这些静态变量

std::vector<const char*> Job::names;
std::vector<bool> Job::percentBased;
std::vector<float> Job::pay;

Job::Job()
{
//.....
std::vector作业::名称;
标准::矢量作业::基于百分比;
std::矢量作业::工资;
作业::作业()
{
//.....

谢谢。我想这是这么简单的事情,但这是我第一次以这种身份使用static。