9

私は見ましたが、他にも答えがあることは知っていますが、私が探しているものを提供してくれるものはないようですので、これを「再投稿」として報告しないでください

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

マイ 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)
4

2 に答える 2

27

「__thiscall」はノイズです。読む。エラー メッセージは について不平を言っていBankAccount::BankAccount(void)ます。ヘッダー ファイルにBankAccountは、デフォルトのコンストラクターがあると書かれていますが、その定義はありません。

于 2012-08-29T18:15:26.350 に答える
7

BankAccount クラスで、引数を取らないコンストラクターを宣言します

 BankAccount();

しかし、あなたはそれを実装していません。これが、リンカがそれを見つけられない理由です。.cpp ファイルでこのコンストラクターの実装を提供すると、リンク手順が機能するはずです。

于 2012-08-29T18:14:55.490 に答える