0

I am creating a model of a bank system in C++, and there are multiple account types, all inheriting from the base class Account. I am unsure exactly what is causing the LNK errors, as I do not believe that I am using external libraries to the compiler, unless it is viewing my .h and .cpp files as external libraries. The error list that I am getting is:

1>------ Build started: Project: Bank, Configuration: Debug Win32 ------
1>  Account.cpp
1>CurrentAccount.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall CurrentAccount::~CurrentAccount(void)" (??1CurrentAccount@@UAE@XZ) referenced in function "public: virtual void * __thiscall CurrentAccount::`scalar deleting destructor'(unsigned int)" (??_GCurrentAccount@@UAEPAXI@Z)
1>H:\C++ Assignment\Bank\Debug\Bank.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

And here is the Account.h file that all of the other classes inherit from

#pragma once
#include "Person.h"
using namespace std;

class Account
{
public: 
    enum AccountType {Current, JrCurrent, StdntSavings, CorpSavings, PersonalLoan, CorpLoan, Mortgage, GuaranteeCard, CreditCard, GFInvestment, EFInvestment, Pension};
    Account(double balance, double interestRate, Person accountHolder);
    Account(double balance, double interestRate, Person accountHolder, AccountType type);
    Account(){};
    virtual ~Account();
    double getBalance(), getInterestRate();
    Person getAccountHolder();
    void deposit(double amount), changeInterest(double newInterest), calculateInterest();
    bool isType(AccountType type);
    bool hasFunds();
    bool withdraw(double amount);
    string toString();

protected:
    Person accountHolder;
    double balance, interestRate, creditLimit;
    AccountType accType;
    friend ostream& operator<<(ostream &out, Account& other);
};

And as an example of how I am inheriting:

#pragma once
#include "Account.h"

class StudentSavings:public Account
{
    //stuff
};
Yann
  • 978
  • 2
  • 12
  • 31
  • 5
    Have you actually implemented the member functions (to be specific, the constructor and destructor) in the `Account` class anywhere? Are you building with that file? – Some programmer dude Nov 25 '13 at 14:22
  • I was implementing 2/3 constructors, and now I only have 1 unresolved external, will update the question – Yann Nov 25 '13 at 14:26
  • 1
    Well now the question is, have you implemented the destructor for `CurrentAccount`? – john Nov 25 '13 at 14:29
  • Ah, wonderful people. Thanks, I guess it comes down to learning how to properly read the error list. I couldn't find out that the error came through unimplemented methods through other googleing. – Yann Nov 25 '13 at 14:33
  • That's what 'unresolved external' means. You declared something (like a method) but you never defined it. – john Nov 25 '13 at 14:37
  • I remember a similar problem; I had to implement the default constructor to solve that. – Pandrei Nov 25 '13 at 15:00

1 Answers1

1

You didn't define your virtual destructor.
The error message clearly tells you that it is this symbol that is not defined.

virtual ~Account() {}

The linker works not just on third-party libraries, but on all definitions and symbols in your own code too. You must provide these when used (and a virtual destructor is always "used").

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055