title: C++ THREAD 1: EXC_BAD_ACCESS(code=1, address =0x8
body: <p>This is my implementation file for my class bankAccount. So, for some reason, the error message keeps pointing out my function getAccountNumber() where it says "return accountNumber" as the problem. I have other classes within this program, but I don't know why it is specifically pointing out the "return accountNumber" command as the problem. I tried initializing my pointer array with nullptr first for each element of my array in my main function, but that didn't seem to work. Any help would be greatly appreciated.  </p>
  
  <pre><code>//
  //  impBankAccount.cpp
  //  Project 3 Bank Account
  //
  //  Created by user on 10/20/18.
  //  Copyright © 2018 user. All rights reserved.
  //
  
  #include &lt;stdio.h&gt;
  #include &lt;string&gt;
  #include &lt;iomanip&gt;
  #include "bankAccount.h"
  #include &lt;iostream&gt;
  
  
  bankAccount :: bankAccount (string n, int acctNumber, double bal){
  
      name = n;
      accountNumber = acctNumber;
      balance = bal;
  
  }
  
  int bankAccount :: getAccountNumber(){
      return accountNumber;
  }
  
  double bankAccount:: getBalance() {
      return balance;
  }
  
  string bankAccount:: getName() {
      return name;
  }
  
  void bankAccount:: setName(string k){
      name = k;
  }
  
  void bankAccount:: withdraw(double k) {
      balance -= k;
  
      toString = to_string(k);
      toString.erase (toString.find_last_not_of('0') + 3, string::npos );
  
      transactionsHistory[currentMonth] += "Withdrawal made: $" + toString + "\n";
  
  }
  
  void bankAccount:: deposit(double l){
      balance += l;
  
      toString = to_string(l);
      toString.erase (toString.find_last_not_of('0') + 3, string::npos );
  
      transactionsHistory[currentMonth] += "Deposit Made: $" + toString + "\n";
  }
  
  void bankAccount:: print() {
      cout &lt;&lt; "Name: " &lt;&lt; name &lt;&lt; endl;
      cout &lt;&lt; "Account Balance: " &lt;&lt; balance &lt;&lt; endl ;
      cout &lt;&lt; "Account Number: " &lt;&lt; accountNumber &lt;&lt; endl;
  }
  
  void bankAccount:: setCurrentMonth(int month){
      currentMonth = month;
  }
  
  
  string bankAccount :: getAccountType(){
      return "Bank Account";
  }
  
  bankAccount :: ~bankAccount() {
  
  
  }
  </code></pre>
  
  <p>This is my code for my main file:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  
  
  #include "bankAccount.h"
  #include "savingsAccount.h"
  #include "highInterestSavings.h"
  #include "noServiceChargeChecking.h"
  #include "serviceChargeChecking.h"
  #include "highInterestChecking.h"
  #include "certificateOfDeposit.h"
  #include "checkingAccount.h"
  
  void program(bankAccount *[]);
  int getAccount(bankAccount *[], int);
  
  
  /*
   Account Types:
  
   Bank Account
   Checking
   Service Charge Checking
   Checking with no service charge
   High Interest Checking
   Certificate of Deposit
   Savings
   High Interest Savings
  
  
  
   */
  
  using namespace std;
  
  int main()
  {
      bankAccount *accountsList[6];
  
  
      program(accountsList);
  
  
  
      accountsList[0] = new savingsAccount("Bill", 10200, 2500);
      accountsList[1] = new highInterestSavings("Susan", 10210, 2000);
      accountsList[2] = new noServiceChargeChecking("John", 20100,3500);
      accountsList[3] = new serviceChargeChecking("Ravi", 30100, 1800);
      accountsList[4] = new highInterestChecking("Sheila", 20200, 6000);
      accountsList[5] = new certificateOfDeposit("Hamid", 51001, 18000, 0.075, 18);
  
  }
  void program(bankAccount *accountList[]){
  
  
  
      int acct = 0;
      int num = 0;
  
  
  
  
      cout &lt;&lt; "What is your account number?";
      cin &gt;&gt; acct;
      num = getAccount(accountList, acct);
  
      cout &lt;&lt; "Welcome to your " &lt;&lt; accountList[num]-&gt;getAccountType() &lt;&lt; " account!";
  } // END MAIN
  
  int getAccount(bankAccount *accountList[], int acct){
  
      int num = 0;
  
      for(int i =0; i&lt;6; i++){
          if (accountList[i]-&gt;getAccountNumber() == acct) {
          num = i;
          break;
          }
      }
      return num;
  }
  </code></pre>