Link 2019 Error

Hi there! I am taking my first C++ course this semester and our assignment was to work on creating a program that tests the given program...? (haha)




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Member-function definitions for class Account.
#include <iostream>
#include "Account.h" // include definition of class Account
using namespace std;

// Account constructor initializes data member balance
Account::Account( int initialBalance )
{
   balance = 0; // assume that the balance begins at 0

   // if initialBalance is greater than 0, set this value as the
   // balance of the Account; otherwise, balance remains 0
   if ( initialBalance > 0 )
      balance = initialBalance;

   // if initialBalance is negative, print error message
   if ( initialBalance < 0 )
      cout << "Error: Initial balance cannot be negative.\n" << endl;
} // end Account constructor

// credit (add) an amount to the account balance
void Account::credit( int amount )
{
   balance = balance + amount; // add amount to balance
} // end function credit

// debit (subtract) an amount from the account balance
void Account::debit( int amount )
{
   if ( amount > balance ) // debit amount exceeds balance
      cout << "Debit amount exceeded account balance.\n" << endl;

   if ( amount <= balance ) // debit amount does not exceed balance
      balance = balance - amount;
} // end function debit

// return the account balance
int main ()
{
	Account accountBalance1 ( 50 );
	Account accountBalance2 ( 25 );
	
	cout << "New balance for Account 1 is: "
		 << accountBalance1.getBalance()
		 << "\n\n New balance for Account 2 is: " 
		 << accountBalance2.getBalance()
		 <<endl;


	system ("pause");



1>------ Build started: Project: Account, Configuration: Debug Win32 ------
1> Account.cpp
1>Account.obj : error LNK2019: unresolved external symbol "public: int __thiscall Account::getBalance(void)" (?getBalance@Account@@QAEHXZ) referenced in function _main
1>C:\Users\documents\visual studio 2010\Projects\Account\Debug\Account.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


If it helps any --- I have already tried setting it to a console type file.
Last edited on
The linker message is very clear. You did not define member function Account::getBalance() that is used in the main.
Topic archived. No new replies allowed.