我遇到了一个让我困扰了很多天的错误。一个快速的谷歌没有给我一个答案。在我看来,代码没有错误,但是当我运行程序时,我得到 9 Unresolved External Symbol(LNK2019) 错误。在尝试破译我的一个错误之后,我相信它发生在一个名为createMortgage
. 这是我对函数的调用。
customers
是一个向量。
for (unsigned int i = 0; i < customers.size(); i++)
{
Customer tempcust = customers.at(i);
if (tempcust.getId() == id)
{
customers.at(i).createMortgage();
}
}
这是函数本身。
void createMortgage(){
int amount;
cout << "Amount?";
cin >> amount;
Mortgage mort(amount);
mortgages.push_back(mort);
}
在这里,尽管它的荣耀,是错误。
Error 4 error LNK2019: unresolved external symbol "public: __thiscall Mortgage::Mortgage(double)" (??0Mortgage@@QAE@N@Z) referenced in function "public: void __thiscall Customer::createMortgage(void)" (?createMortgage@Customer@@QAEXXZ) F:\C++ assignment (Real)\C++ assignment (Real)\Driver.obj C++ assignment (Real)
这是我的抵押 .h 文件。
#pragma once
//#include <iostream>
//#include <String>
class Mortgage
{
private:
int id;
double amount;
public:
Mortgage(double amount);
double getAmount();
int getId();
};
这是我的抵押贷款 .cpp 文件。
#pragma once
extern int idcreation;
class Mortgage
{
int id;
double amount;
Mortgage(double amount)
{
this -> amount = amount;
this -> id = idcreation;
idcreation++;
}
int getId(){
return id;
}
double getAmount(){
return amount;
}