Undefined References

I just finished typing up the last few functions for bank_accounts.cpp, and I'm getting two undefined references. How do I fix these? I've read that it has something to do with linking, but we never discussed that in class so I'm clueless about it.
My error:
1
2
3
4
5
6
g++ bank_accounts.o account.o checking.o savings.o -o bank_accounts
bank_accounts.o: In function `main':
bank_accounts.cpp:(.text+0x14a): undefined reference to `checking_deposit(std::basic_ofstream<char, std::char_traits<char> >&, Checking&)'
bank_accounts.cpp:(.text+0x17d): undefined reference to `saving_withdraw(std::basic_ofstream<char, std::char_traits<char> >&, Savings&)'
collect2: ld returned 1 exit status
make: *** [bank_accounts] Error 1 


bank_accounts.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <iostream>
#include <fstream>
#include "account.h"
#include "savings.h"
#include "checking.h"

using namespace std;

int menu(ofstream&);
void savings_deposit(ofstream&, Savings&);
void checking_deposit(ofstream&, Checking&);
void saving_withdraw(ofstream&, Savings&);
void checking_withdraw(ofstream&, Checking&);
void new_month(Checking&, Savings&);

int main(int argc, char * argv[])
{
  if(!(argc > 1))
  {
    return 1;
  }

  Checking check(0.0, 0.05);
  Savings save(0.0, 0.05);

  ofstream ofile(argv[1], ios::out);
  if(!(ofile.is_open()))
  {
    std::cout << "Error writing to file";
    return 1;
  }

  ofile << "\n\n" << endl;
  int proceed = menu(ofile);

  if(proceed == 6)
    return 0;

  while(proceed != 6)
  {
    if(proceed == 1)
    {
      savings_deposit(ofile, save);
      proceed = menu(ofile);
    } else if(proceed == 2)
    {
      checking_deposit(ofile, check);
      proceed = menu(ofile);
    } else if(proceed == 3)
    {
      saving_withdraw(ofile, save);
      proceed = menu(ofile);
    } else if(proceed == 4)
    {
      checking_withdraw(ofile, check);
      proceed = menu(ofile);
    } else if(proceed == 5)
    {
      new_month(check, save);
      proceed = menu(ofile);
    }
   }
  ofile.close();
  return 0;
}

int menu(ofstream &ofile)
{
  ofile << "  ******** BANK ACCOUNT MENU ********  " << endl;
  ofile << "\n" << "1.  Savings Account Deposit" << endl;
  ofile << "2.  Checking Account Deposit" << endl;
  ofile << "3.  Savings Account Withdrawal" << endl;
  ofile << "4.  Checking Account Withdrawal" << endl;
  ofile << "5.  Update and Display Account Statistics" << endl;
  ofile << "6.  Exit" << "\n" << endl;

  ofile << "Your choice, please: (1-6)";

  int choice;
  cin >> choice;
  return choice;
}

void savings_deposit(ofstream& ofile, Savings& save)
{
  ofile << " Enter amount to deposit:" << endl;
  double amount;
  cin >> amount;
  save.deposit(amount);
}

void checking_deposit(ostream& ofile, Checking& check)
{
  ofile << " Enter amount to deposit: " << endl;
  double amount;
  cin >> amount;
  check.deposit(amount);
}

void saving_withdraw(ostream& ofile, Savings& save)
{
  ofile << "Enter amount to withdraw: " << endl;
  double amount;
  cin >> amount;
  save.withdraw(amount);
}

void checking_withdraw(ofstream& ofile, Checking& check)
{
  ofile << "Enter amount to withdraw: " << endl;
  double amount;
  cin >> amount;
  check.withdraw(amount);
}

void new_month(Checking& check, Savings& save)
{
  save.monthlyProc();
  check.monthlyProc();
}


savings.cpp
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
#include "savings.h"

Savings::Savings(double balance, double intRate) : Account()
{
  Account::balance = balance;
  Account::intRate = intRate;
  status = true;
}

void Savings::withdraw(double with)
{
  if(status)
    Account::withdraw(with);
  if(balance < 25.0)
    status = false;
}

void Savings::deposit(double dep)
{
  if(!status)
  {
    Account::deposit(dep);
    if(Account::getTotal() > 25.0)
    {
      status = true;
    }
  } else
  {
    Account::deposit(dep);
  }
}

void Savings::monthlyProc()
{
  if(Account::getWithdrawals() > 4)
  {
    double total = Account::getWithdrawals();
    total -= 4;
    Account::serviceCharges += total;
  }
  Account::monthlyProc();
  if(Account::balance < 25.0)
  {
    status = false;
  }
}


checking.cpp
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
Checking::Checking(double balance, double intRate) : Account()
{
  Account::balance = balance;
  Account::intRate = intRate;
}

void Checking::withdraw(double with)
{
 if(Account::balance - with < 0.0)
 {
   Account::serviceCharges += 15.0;
 } else
 {
   Account::withdraw(with);
 }
}

void Checking::deposit(double dep)
{
 Account::deposit(dep);
}

void Checking::monthlyProc()
{
  double temp = Account::withdrawals * 0.10;
  temp = temp + 5.0;
  Account::serviceCharges += temp;
  Account::monthlyProc();
}
declaration - void checking_deposit(ofstream& ofile, Checking& check);
definition - void checking_deposit(ostream& ofile, Checking& check)
Same for the other error.

May I inquire as to why you are directing your menu and other output to a file?
I'm sorry but what you put makes no sense. Is there somewhere in my code where I forgot to put a semi-colon or put one where it wasn't needed?

It's a school project, and our teacher wants us to direct it to a file so it's easier for grading.
Ah, gotcha.

Let me try this again:
declaration - void checking_deposit(ofstream& ofile, Checking& check);
definition - void checking_deposit(ostream& ofile, Checking& check)
Notice the missing f?
gotcha, thank you. I can't believe I missed that.
Topic archived. No new replies allowed.