未解决的外部符号“public:__ thiscall

时间:2012-08-29 18:12:34

标签: c++

我看了,我知道还有其他的答案但是他们似乎都没有给我我想要的东西,所以请不要将此作为"转发"

我得到了未解决的外部符号" public:__ thishisall"我的C ++代码中的错误,我即将把它踢出窗口而且我的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

我的BankAccount 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)

2 个答案:

答案 0 :(得分:21)

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

答案 1 :(得分:6)

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

 BankAccount();

但你没有实现它。这就是链接器无法找到它的原因。在.cpp文件中为此构造函数提供实现,并且链接步骤应该有效。