Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess violation help C++
    text
    copied!<p>I am currently getting this error in my code: Unhandled exception at 0x0FF321E8 (msvcp110d.dll) in bankAccountp5.exe: 0xC0000005: Access violation writing location 0xCCCCCCF8. And I'm certain it's to do with an array of objects I have created.</p> <p>Here is part of my code: </p> <pre><code>class bankAccount: public bankBranch { public: bankAccount(int, int, int, string, int); int setAccountNumber () { bankAccountNumber = ++minAccountNumber; return this-&gt;bankAccountNumber; } void setAccountBalance () { for(i = 0; i &lt; getNumOfBankAccounts(); i++) { cout &lt;&lt; "Enter the balance for your bank Account: " &lt;&lt; endl; cin &gt;&gt; accounts[i]-&gt;bankAccountBalance; if (bankAccountBalance &gt; MAX_BALANCE || bankAccountBalance &lt; MIN_BALANCE) { cout &lt;&lt; "Incorrect bank balance, please try again!" &lt;&lt; endl; --i; } else { ++i; } } } void menuSystem(int choice) { } void displayBankBranchDetails() { cout &lt;&lt; "\n"; cout &lt;&lt; "DETAILS OF YOUR BANK BRANCH" &lt;&lt; endl; cout &lt;&lt; "BSB Number: " &lt;&lt; this-&gt;getBsbNumber() &lt;&lt; endl; cout &lt;&lt; "Address: " &lt;&lt; this-&gt;getAddress() &lt;&lt; endl; cout &lt;&lt; "Postal code: " &lt;&lt; this-&gt;getPostCode() &lt;&lt; endl; } void setBankAccountDetails() { } int getNumOfBankAccounts() { return this-&gt;numOfBankAccounts; } void createBankAccounts() { valid = false; while (valid == false) { cout &lt;&lt; "How many Bank Accounts would you like to create under the Bank Branch BSB: " &lt;&lt; getBsbNumber() &lt;&lt; endl; cin &gt;&gt; numOfBankAccounts; if ( numOfBankAccounts &lt;= MAX_NUMBER_ACCOUNTS) { valid = true; } else { valid = false; } } } private: //bankAccount Data int bankAccountNumber; int numOfBankAccounts; int bankAccountBalance; int interestRate; //constants const static int MAX_NUMBER_ACCOUNTS = 10; const static int MAX_BALANCE = 100000; const static int MIN_BALANCE = 0; //objects bankBranch homeBranch; bankAccount* accounts[MAX_NUM_ACCOUNTS]; //misc int minAccountNumber; int i; bool valid; }; </code></pre> <p>The error occurs when I get to void setAccountBalance(), and I call the array of objects accounts, could anyone help me out with this? Cheers.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload