Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble with fields initialized via pointer
    primarykey
    data
    text
    <p>My problem involves the following function:</p> <pre><code>/*Adds the transaction to the head of the linked list attached to the account.*/ void Bank::Worker::UpdateTransactionHistory(int account_number, string transaction, Bank *our_bank_ptr) { transaction_node new_trans; new_trans.transaction = transaction; if (our_bank_ptr-&gt;accounts[account_number].head == nullptr) { //If this is the first transaction our_bank_ptr-&gt;accounts[account_number].head = &amp;new_trans; } else { //If this isn't the first transaction, disconnect the account from its current transaction list, connect the new transaction to the account and then connect the old list to the new transaction. transaction_node temp; temp = *(our_bank_ptr-&gt;accounts[account_number].head); our_bank_ptr-&gt;accounts[account_number].head = &amp;new_trans; new_trans.next = &amp;temp; } if (our_bank_ptr-&gt;accounts[account_number].head) //here the correct string is printed cout &lt;&lt; our_bank_ptr-&gt;accounts[account_number].head-&gt;transaction; } </code></pre> <p>Its meant to update the transaction field of new_trans, which is then linked to the rest of the transaction list for a given account. Just before I return from the update transaction function I test to make sure the string was added in properly. The very last line of the function is <code>cout &lt;&lt; our_bank_ptr-&gt;accounts[account_number].head-&gt;transaction;</code>,which outputs the transaction string correctly. </p> <p>However, when I return from the function and immediately invoke the <em>exact same</em> line of code the compiler tells me that the transaction field the function updated still uninitialized. This is despite the fact that it was passed in as a pointer.</p> <p>What the heck!? I thought that if I pass info into a function via pointers that anything I did to that info over the course of the function was permanent? What am I missing here?</p> <p>Thank for your help,</p> <p>Adam</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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