title: calling a function through a pointer - access violation reading location
body: <p>I have a function that returns a <code>Customer</code> object (not pointer) like this:</p>
  
  <pre><code>Customer CustomerList::retrieve(const int index) const{
          if (index&lt;1 || index&gt;size)
                  return false;
          else{
                  Node *cur = find(index);
                  return (cur-&gt;data);
          }
  }
  </code></pre>
  
  <p>This function gets a <code>Customer</code> object from a <code>CustomerList</code>(which is a linkedlist).</p>
  
  <p>I'm trying to manipulate the <code>Customer</code> in the list with following function(this function adds an <code>Account</code> to the <code>Customer</code> object.)</p>
  
  <pre><code>list.retrieve(i).addAccount(acc);
  </code></pre>
  
  <p>However after this function call, <code>Customer</code> object in <code>CustomerList</code> doesn't change. I assume that the reason is I return a copy of a <code>Customer</code> object, not the object itself. </p>
  
  <p>So in order to return the adress of Customer and manipulate it correctly, i make the following changes to my function.</p>
  
  <pre><code>Customer* CustomerList::retrieve(const int index) const{
          if (index&lt;1 || index&gt;size)
                  return false;
          else{
                  Node *cur = find(index);
                  return &amp;(cur-&gt;data);
          }
  }
  </code></pre>
  
  <p>And call the manipulating function like that:</p>
  
  <pre><code>list.retrieve(i)-&gt;addAccount(acc);
  </code></pre>
  
  <p>But it gives me a <strong>"Access violation reading location 0x00000044."</strong> error. What I want to learn is:</p>
  
  <ol>
  <li>Why doesn't it manipulate the <code>Customer</code> object in first place? Is my assumption right?</li>
  <li>After I change my functions and function calls, why does it gives me the error I mentioned above?</li>
  </ol>