2012-08-29 41 views
5

我已经看过,我知道有其他的答案在那里,但他们都不给我什么我要找的,所以请不要报告为‘重新发布’解析的外部符号“公用:__thiscall

我得到解析外部符号。“市民:__thiscall”错误在我的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)" ([email protected]@[email protected]) referenced in function "public: __thiscall SavingsAccount::SavingsAccount(void)" ([email protected]@[email protected]) 

1>CheckingAccount.obj : error LNK2001: unresolved external symbol "public: __thiscall BankAccount::BankAccount(void)" ([email protected]@[email protected]) 
+0

当您看到这些类型的错误时,请确保您不会忘记链接到LIB文件。有时添加标头是不够的,即使是WinAPI的东西。 –

回答

18

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

+0

@MattWestlake - 我知道这种感觉。这些错误消息中有很多信息,但它们相当密集。 –

+0

为什么MS Studio在其错误信息中如此神秘?为什么不必要的噪音? –

+1

@ JavierQuevedo-Fernández--因为在不同的背景下,“噪音”可能很重要。只有编译器才能生成有意义的错误消息。成为一名优秀程序员的一部分是学习理解错误消息。 –

4

在你的类BankAccount声明一个构造函数没有参数

BankAccount(); 

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

+0

我一直在寻找代码的方式太长... ugh –

+0

@MattWestlake它发生在每个人身上。一般来说,链接器错误通常意味着你忘记了实现一个函数,或者你没有链接到正确的库。这些通常是要寻找的第一件事。 – mathematician1975

相关问题