title: Dynamic memory allocation being overwritten?
body: <p>I am having massive problems with my code. I do not understand why this is happening and having no idea how to fix it.</p>
  
  <p>Basically I have tried to define an array of pointers to characters where each element of the array of pointers stores a different set of characters.</p>
  
  <p><strong>Class constructor:</strong>
  (note: size is an integer which specifies how large my array of pointers should be, the user can define this)</p>
  
  <pre><code>storeElements = new char*[size]; 
  </code></pre>
  
  <p>Say the size = 3, now storeElements should be an array of pointers capable of pointing to 3 separate strings of characters.</p>
  
  <pre><code>*storeElements = "one"; 
  *(storeElements+1) = "two"; 
  *(storeElements+2) = "three"; 
  </code></pre>
  
  <p>When I print these values straight after assigning them, they print the correct strings, however later on in my code, in other functions and after many other variables have been declared, and I have opened an output text file, *storeElements kind of gets muddled up.</p>
  
  <p>Say for example, if I tried to do this (later on in my code):</p>
  
  <pre><code>cout &lt;&lt; *(storeElements+2) &lt;&lt; endl;
  </code></pre>
  
  <p><strong>Instead of printing "three" it might print "one" or nothing at all.</strong></p>
  
  <p>There has got to be a problem with dynamic memory allocation here because I am reading from text files and sometimes the contents of that text file gets stored in the elements of *storeElements <strong>without me assigning them to *storeElements at all</strong></p>
  
  <p>Please help me better understand how to fix this. I've invested a lot of time and effort into my code and am very upset over this. Thank you for taking the time out of your day to help me.</p>