C++ 未解析的外部符号“公共:__thiscall
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12184027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
unresolved external symbol "public: __thiscall
提问by Matt Westlake
I have looked and I know there are other answers out there but none of them seem to give me what i'm looking for so please don't report this as a "repost"
我看过了,我知道还有其他答案,但似乎没有一个给我我正在寻找的东西,所以请不要将此报告为“重新发布”
I'm getting the unresolved external symbol "public: __thiscall" error in my C++ code and i'm about to kick it out the window and just fail my C++ class. Please help me!!!!
我在我的 C++ 代码中遇到了未解析的外部符号“public: __thiscall”错误,我正准备将它踢出窗口并让我的 C++ 类失败。请帮我!!!!
My checking account header file
我的支票账户头文件
#include "BankAccount.h"
class CheckingAccount
{
private:
int numOfWithdrawls;
double serviceFee;
int AccountBal;
public:
bool withdraw (double wAmmt);
BankAccount CA;
CheckingAccount();
CheckingAccount(int accountNum);
};
and its CPP file
及其CPP文件
#include <iostream>
using namespace std;
#include "CheckingAccount.h"
CheckingAccount::CheckingAccount()
{
CA;
numOfWithdrawls = 0;
serviceFee = .50;
}
CheckingAccount::CheckingAccount(int accountNum)
{
CA.setAcctNum (accountNum);
numOfWithdrawls = 0;
serviceFee = .50;
}
bool CheckingAccount::withdraw (double wAmmt)
{
numOfWithdrawls++;
if (numOfWithdrawls < 3)
{
CA.withdraw(wAmmt);
}
else
{
if (CA.getAcctBal() + .50 <=0)
{
return 0;
}
else
{
CA.withdraw(wAmmt + .50);
return 1;
}
}
}
My BankAccount header file
我的银行账户头文件
#ifndef BankAccount_h
#define BankAccount_h
class BankAccount
{
private:
int acctNum;
double acctBal;
public:
BankAccount();
BankAccount(int AccountNumber);
bool setAcctNum(int aNum);
int getAcctNum();
double getAcctBal();
bool deposit(double dAmmt);
bool withdraw(double wAmmt);
};
#endif
My BankAccount CPP file
我的银行账户 CPP 文件
#include <iostream>
using namespace std;
#include "BankAccount.h"
BankAccount::BankAccount(int AccoutNumber)
{
acctNum = 00000;
acctBal = 100.00;
}
bool BankAccount::setAcctNum(int aNum)
{
acctNum = aNum;
return true;
}
int BankAccount::getAcctNum()
{
return acctNum;
}
double BankAccount::getAcctBal()
{
return acctBal;
}
bool BankAccount::deposit(double dAmmt)
{
acctBal += dAmmt;
return true;
}
bool BankAccount::withdraw(double wAmmt)
{
if (acctBal - wAmmt <0)
{
return 0;
}
else
{
acctBal -= wAmmt;
return 1;
}
}
My error:
我的错误:
1>BankAccountMain.obj : error LNK2019: unresolved external symbol "public: __thiscall BankAccount::BankAccount(void)" (??0BankAccount@@QAE@XZ) referenced in function "public: __thiscall SavingsAccount::SavingsAccount(void)" (??0SavingsAccount@@QAE@XZ)
1>CheckingAccount.obj : error LNK2001: unresolved external symbol "public: __thiscall BankAccount::BankAccount(void)" (??0BankAccount@@QAE@XZ)
回答by Pete Becker
The "__thiscall" is noise. Read on. The error messages are complaining about BankAccount::BankAccount(void)
. The header file says that BankAccount
has a default constructor, but there's no definition for it.
“__thiscall”是噪音。继续阅读。错误消息抱怨BankAccount::BankAccount(void)
. 头文件说它BankAccount
有一个默认构造函数,但没有定义。
回答by mathematician1975
In your BankAccount class you declare a constructor that takes no arguments
在您的 BankAccount 类中,您声明了一个不带参数的构造函数
BankAccount();
but you do not implement it. This is why the linker cannot find it. Provide an implementation for this constructor in your .cpp file and the link step should work.
但你没有实施它。这就是链接器找不到它的原因。在您的 .cpp 文件中为此构造函数提供一个实现,链接步骤应该可以工作。