title: Segmentation fault trying to dereference a pointer from a vector of pointers
body: <p>I have a vector of pointers to objects that I am iterating through using std::vector::iterator`.  Since the element returned is itself a pointer I dereference the iterator twice, once to return the pointer and once to resolve the pointer to the actual object.  </p>
  
  <p>I'm trying to invoke a member function (<code>getClass</code>) that returns an std::string and I have tried both <code>(**it).getClass()</code> and <code>(*it)-&gt;getClass()</code> but both give me a segmentation fault.  I keep feeling like I'm missing something obvious.</p>
  
  <p>partial function code:</p>
  
  <pre><code>void dataSet::createFolds()
  {
     // Shuffle the data vector
     std::random_shuffle( m_records.begin(), m_records.end());
  
     std::cout &lt;&lt; "STARTING MAIN LOOP.  THERE ARE " &lt;&lt; m_records.size() &lt;&lt; " RECORDS\n";
     // iterate through the data vector and assign each to a fold
     std::vector&lt;dataRecord *&gt;::iterator it = m_records.begin();
     while (it != m_records.end())
     {
        std::string currentClass = (*it)-&gt;getClass();  // SEG FAULT HERE
        .
        .
        .
     }
     .
     .
     .
  }
  </code></pre>
  
  <p>The vector is m_records ... <a href="http://pastebin.com/pw8bQyc2" rel="nofollow">code</a> </p>
  
  <p>dataRecord is defined like this ... <a href="http://pastebin.com/5c86tYGG" rel="nofollow">code</a></p>
  
  <p>In response to questions about filling the vector:</p>
  
  <p>The data is read from a text file and I really don't want to post the entire thing unless I have to (212 lines) but the pertinent code for populating the vector is below.  The constructor for the dataRecord object takes a vector of field objects.  I use a temporary pointer, use new to create the object then push_back the pointer.</p>
  
  <pre><code>while ...
  {
     std::vector&lt;field&gt; fields;
  
     // build the fields vector
     for (unsigned int i = 0; i &lt; numAttribs; ++i)
        fields.push_back(field(data.at(i), attribTypes[i]));
  
     // create the new dataRecord
     dataRecord * newRecord = new dataRecord(fields);
  
     // add the record to the set
     m_records.push_back(newRecord);
  
     ++recordNum;
     std::cout &lt;&lt; "read record " &lt;&lt; recordNum &lt;&lt; std::endl;
  }
  </code></pre>