title: Pointer to class data returning string with empty value, yet keeping int value's. c++
body: <p>This is a puzzling problem, and I honestly am having a hard time figuring out what code to 
  post. The base of the code is simple, however. I am using a command file, that takes a char, 
  and based on that char, does several different things.</p>
  
  <p>If char = 'D' then assign data, create a node which contains a pointer to that data, and "push_back" that node onto a linked list.</p>
  
  <p>Simple enough right? Well, my problem comes when char = 'P' and we have to print out the data based off of the number (ID) that is supplied. </p>
  
  <p>So simply put, if char = 'P', it takes the ID signified after 'P', iterates through the linked list, returns a pointer to the node that contains that ID in the node's data, and prints off the data in that node.</p>
  
  <p>What happens is weird.... it manages to print out any form of data that the pointer points to that is an int, but for the strings, the value's are "" (Empty strings). I found this out when I debugged it with VS, and it showed the values of my 'label' and 'sequence' respectively.</p>
  
  <p>I managed to go further and saw that the values for the strings are infact being put into the list, because when I debug my 'push_back' function, it lists the values for label and sequence correctly without empty strings.</p>
  
  <p>my print method:</p>
  
  <pre><code>//Print Method
  
  void DNA::printDNA()
  {
      cout &lt;&lt; "DNA:" &lt;&lt; '\t' &lt;&lt; "label: " &lt;&lt; label &lt;&lt; '\t' &lt;&lt; "ID: " &lt;&lt; ID &lt;&lt; '\t' &lt;&lt; "Sequence: "
          &lt;&lt; sequence &lt;&lt; endl &lt;&lt; "Length: " &lt;&lt; length &lt;&lt; '\t' &lt;&lt; "cDNAStartIndex: " &lt;&lt; index &lt;&lt; endl &lt;&lt; endl;
  }
  </code></pre>
  
  <p>Now this is the code that I was talking about, in my 'push_back' function, the values are listed as they should be for 'data', as the strings are NOT empty when I debugged with a breakpoint to show the values.</p>
  
  <p>here is the source with this function: </p>
  
  <pre><code>DNAList::DNAList()
  {
      head = new DNANode;
      head -&gt; next = NULL;
  
  
  }
  
  void DNAList::push_back(DNA* newDNA)
  {
      DNANode * last;
      DNANode * cur;
      DNANode * ptr = new DNANode;
      ptr -&gt; data = newDNA;
      last = NULL;
      cur = head;
      cout &lt;&lt; "Note: Adding " &lt;&lt; newDNA -&gt; getID() &lt;&lt; " ..." &lt;&lt; endl &lt;&lt; endl;
      while(cur!= NULL)
      {
          last = cur;
          cur = cur -&gt; next;
      }
  
      if(cur == head -&gt; next)
      {
          ptr -&gt; next = NULL;
          ptr -&gt; prev = head;
          head -&gt; next = ptr;
      }
      else
      {
          ptr -&gt; next = cur;
          ptr -&gt; prev = last;
          last -&gt; next = ptr;
      }
  
  }
  </code></pre>
  
  <p>Ok, so in my mind, the node data that was pushed onto the linked list has the strings correct? Here is the class leading up to the push back to give you an idea of what im dealing with:</p>
  
  <pre><code>void SequenceDatabase::importEntries(string name)
  {
      ifstream file;
      file.open(name);
  
      if(!file.is_open())
      {
          cout &lt;&lt; "Error opening file!" &lt;&lt; endl;
          exit(1);
      }
  
      char letter;
      string label, sequence;
      int ID, length, index;
      int added;
      added = 0;
      while(file)
      {
          DNA * ptr;
          file  &gt;&gt; letter;
          if(letter == 'D' || letter == 'd')  
          {
              file &gt;&gt; label &gt;&gt; ID &gt;&gt; sequence &gt;&gt; length &gt;&gt; index;
              DNA data(label,ID,sequence,length,index);
              ptr = &amp;data;
              list.push_back(ptr);
              added++;
          }       
          if(letter == 'O' || letter == 'o')
          {
              file &gt;&gt; ID;
              list.obliterate(ID);
          }
  
          if(letter == 'P' || letter == 'p')
          {
              file &gt;&gt; ID;
              cout &lt;&lt; "Note: Printing " &lt;&lt; ID &lt;&lt; " ..." &lt;&lt; endl &lt;&lt; endl;
              ptr = list.findID(ID);
              if(ptr == NULL)
              {
                  cout &lt;&lt;"Error printing " &lt;&lt; ID &lt;&lt; " . Not found in list." &lt;&lt; endl &lt;&lt; endl;
              }
              else
              ptr -&gt; printDNA();
  </code></pre>
  
  <p>So as an example, lets say I have the commands:
  D HORSE 1114252 ccgaccagggg 25 -1
  P 1114252 (ID)
  it prints off as follows:</p>
  
  <p>DNA:    label:  ID: 1114252 Sequence: 
  Length: 25  cDNAStartIndex: -1</p>