9

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!!!!

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

#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

#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)
Jens
  • 67,715
  • 15
  • 98
  • 113
Matt Westlake
  • 3,499
  • 7
  • 39
  • 80
  • When you see these kinds of errors, make sure you aren't forgetting to link to a LIB file. Sometimes adding the headers is not enough, even for WinAPI stuff. – kayleeFrye_onDeck Sep 21 '17 at 20:34

2 Answers2

28

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.

Pete Becker
  • 74,985
  • 8
  • 76
  • 165
  • @MattWestlake - I know the feeling. There's a lot of information in those error messages, but they're rather dense. – Pete Becker Aug 29 '12 at 18:20
  • Why is MS Studio so cryptic in its error messages? Why the unnecessary noise? – Javier Quevedo Aug 17 '16 at 12:43
  • 2
    @JavierQuevedo-Fernández - because in a different context, the "noise" might matter. There's only so much a compiler can do to generate meaningful error messages. Part of becoming a good programmer is learning to understand error messages. – Pete Becker Aug 17 '16 at 12:54
7

In your BankAccount class you declare a constructor that takes no arguments

 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.

mathematician1975
  • 21,161
  • 6
  • 59
  • 101
  • I've been looking at code way too long... ugh – Matt Westlake Aug 29 '12 at 18:19
  • @MattWestlake It happens to everyone. In general linker errors usually mean that you have forgotten to implement a function or you have failed to link to the correct library. These are usually the first things to look for. – mathematician1975 Aug 29 '12 at 18:22