链接器错误2001无法解析的外部符号
linker error 2001 unresolved external symbols
我以前从来没有遇到过这样的错误,请记住,我还在上学,所以我没有做过很长时间。
我得到的错误是:错误1错误LNK2001:未解析的外部符号"private: static class std::vector> Job::names" (?names@Job@@0V?$vector@PBDV?$allocator@PBD@std@@@std@@A) Job。obj PayrollCalculator
错误2错误LNK2001:未解析的外部符号"private: static class std::vector> Job::percentBased" (?percentBased@Job@@0V?$vector@_NV?$allocator@_N@std@@@std@@A)作业。obj PayrollCalculator
错误3错误LNK2001:未解析的外部符号"private: static class std::vector> Job::pay" (?pay@Job@@0V?$vector@MV?$allocator@M@std@@@std@@A) Job。obj PayrollCalculator
我不知道从哪里开始这样的错误,如果有人可以帮助。下面是相关代码,如果有帮助的话:
stdafx.h:
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <string>
#include <iostream>
#include <limits>
#include <vector>
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();
};
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];
}
如果需要的话,我也在使用visual studio 2013。
您只在Job.h文件中声明了names, percentBased, pay
,您需要在Job.cpp
std::vector<const char*> Job::names;
std::vector<bool> Job::percentBased;
std::vector<float> Job::pay;
Job::Job()
{
//.....
相关文章:
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 未解析的外部符号_MsiLocateComponentW@12.
- 在C++中使用 gRPC 时未解析的外部符号
- LibPrivoxy: 未解析的外部符号 __declspec(dllimport) int __stdcall Sta
- 尝试从 XamlApplication 编译 C++/WinRT 空白应用程序时,我收到未解析的外部符号 winrt_make_*
- 我收到错误LNK2001:未解析的外部符号(C++代码)
- 可视抽象类 c++(错误 LNK 2001:未解析的外部符号)
- 如何摆脱C++中未解析的外部符号"private: static char"错误?
- 当 lib 已添加到其他依赖项时,如何在 VS 中调试未解析的外部符号错误
- 仅在少数方法(静态或共享库)中解析的外部符号
- 未解析的外部符号"__declspec(dllimport)与 Spdlog c++ 库
- 函数 _main (OPENGL C++) 中引用的未解析的外部符号 ________
- 错误LNK2019未解析的外部符号"public: __thiscall SLinkList<char>::SLinkList<char>(void)"
- 使用静态 constexpr 成员的未解析外部符号
- 引入参数化构造函数后显示 LNK 2019 未解析外部符号的代码错误
- Dlib LNK2001未解析的外部符号USER_ERROR__consistent_build_configurati
- 矛盾的未解决的外部符号+未使用的库与VS2017和FFMPEG 4
- 链接器错误:切换到unicode生成给出:未解析的外部符号WinMain
- 类模板上一个特定函数的未解析外部符号
- LNK2001:未解析的外部符号public:static类std::vector