未解析的外部符号"公共:__thiscall

unresolved external symbol "public: __thiscall

本文关键字:公共 thiscall 符号 外部      更新时间:2023-10-16

我看过,我知道还有其他答案,但似乎没有一个能告诉我我在寻找什么,所以请不要将其报告为"转发"

我在C++代码中遇到了未解决的外部符号"public:__thiscall"错误,我正要把它踢出窗口,让我的C++类失败。请帮帮我!!!!

我的支票账户头文件

#include "BankAccount.h"
class CheckingAccount
{
private:
int numOfWithdrawls;
double serviceFee;
int AccountBal;
public:
bool withdraw (double wAmmt);
BankAccount CA;
CheckingAccount();
CheckingAccount(int accountNum);
};

及其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;
    }
}
}

我的BankAccount头文件

#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

我的银行账户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;
}
}

我的错误:

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)

"__thiscall"是噪声。继续阅读。错误消息抱怨BankAccount::BankAccount(void)。头文件说BankAccount有一个默认的构造函数,但没有定义

在BankAccount类中,您声明了一个不带参数的构造函数

 BankAccount();

但您没有实现它。这就是链接器找不到它的原因。在.cpp文件中提供此构造函数的实现,链接步骤应该可以工作。