title: Storing std::string and custom object in std::pair
body: <p>I am programming my own implementation of a hash table. For this project I have an array of <code>std::list</code> which is my table where I store the data. Every list consists of <code>std::pair</code> objects. A pair contains a <code>std::string</code> (name of a person) and a pointer to an object of a custom class (class that contains data about the person). </p>
  
  <p>I have a problem with the implementation of a put() method for inserting data in the hash table. This is the code I wrote.</p>
  
  <pre><code>pair&lt;string,StudentRecord*&gt;* HashTable::put(string&amp; p_Name, StudentRecord* p_StudentRecord){
  
  
      std::pair&lt;std::string, StudentRecord*&gt; ptr = { p_Name, p_StudentRecord };
      this-&gt;put(&amp;ptr);
      return &amp;ptr;
  }
  
  void HashTable::put(pair&lt;string, StudentRecord*&gt;* p_HTElement){
  
      string key = p_HTElement-&gt;first;
      int storage_place = this-&gt;m_Hasher-&gt;hash(key) % this-&gt;m_Capacity;
      this-&gt;m_Table[storage_place].push_back(p_HTElement);
      this-&gt;m_NumberOfEntries++;
      this-&gt;updateLoadFactor();
  
      if (this-&gt;m_LoadFactor &gt;= MAX_LOAD_FACTOR)
          this-&gt;rehash();
  }
  </code></pre>
  
  <p>When data needs to be added the first method is called. This method creates a <code>std::pair</code> object and passes a reference to this object to the second method. The second method then calculates the hash and places it in the array of std::list. However the problem is that after putting it in the array the <code>std::string</code> (the first element of the pair) isn't readable anymore. When I look with the debugger it just says its value is "". When in a later stage I want to find the data in the hash table my method printHashTable() does recognises their is a pair in the list, but it can't read the data. Again with the debugger it says </p>
  
  <blockquote>
    <p>error reading characters of string</p>
  </blockquote>
  
  <p>for the first element of the pair and for the custom object it says <code>0xccccccccc</code></p>
  
  <p>This is my method which needs to print all the data in the hash table:</p>
  
  <pre><code>void HashTable::printTable(){
      for (int i = 0; i &lt; this-&gt;m_Capacity; i++){
          if (!this-&gt;m_Table[i].empty()) {
              for (std::list&lt;std::pair&lt;std::string, StudentRecord*&gt;*&gt;::iterator element = this-&gt;m_Table[i].begin(); element != this-&gt;m_Table[i].end(); ++element) {
                  cout &lt;&lt; (*element)-&gt;first &lt;&lt; endl;
              }
          }
      }
  }
  </code></pre>