title: A private vector of pointers pointing to objects. How to access those objects with getter method?
body: <p>My program is six iterations of a loop in which eight people vote for one another. Who each person votes for during each iteration is saved to the private class member <code>voteList</code> (a vector of pointers).</p>
  
  <p>My trouble is that at the end of the six iterations, I want to be able to say, for example, who Anna voted for during each vote, using the <code>GetVote(int)</code> public method I wrote.</p>
  
  <p><code>*(voteList[round])</code> should be the value (a person) of who Anna voted for in a given round, I think? And using the <code>GetName()</code> method should retrieve the string of that person's name. But no matter how I fiddle with it, the program crashes whenever I call <code>GetVote()</code>.</p>
  
  <p>I'm sure I've made one or more really stupid mistakes, but I can't figure out what the problem is. Any input would be appreciated!</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;random&gt;
  #include &lt;time.h&gt;
  using namespace std;
  
  enum gender { male, female };
  
  class Person {
      private:
          string personName;
          gender personGender;
          vector&lt;Person *&gt; voteList;
      public:
          // Constructors
          Person (string, gender);
          // Setters
          void Vote (Person * target) {
              voteList.push_back (target); 
          };
          // Getters
          string GetName () { return personName; };
          string GetVote (int round)
          {
              Person ugh = *(voteList[round]);
              return ugh.GetName ();
          };
  };
  
  Person::Person (string a, gender b) {
      personName = a;
      personGender = b; }
  
  void Voting (vector&lt;Person&gt; voters)
  {
      for (int i = 0; i &lt; voters.size(); i++) {
          int number = (rand() % voters.size());
          Person * myTarget = &amp;voters[number];
          voters[i].Vote (myTarget);
          cout &lt;&lt; voters[i].GetName() &lt;&lt; " votes for " &lt;&lt; voters[number].GetName() &lt;&lt; endl;
      }
      cout &lt;&lt; endl;
  }
  
  int main()
  {
      srand(time(0));
  
      Person Anna ("Anna", female);
      Person Baxter ("Baxter", male);
      Person Caroline ("Caroline", female);
      Person David ("David", male);
      Person Erin ("Erin", female);
      Person Frank ("Frank", male);
      Person Gemma ("Gemma", female);
      Person Hassan ("Hassan", male);
  
      vector&lt;Person&gt; theGroup;
      theGroup.push_back (Anna);
      theGroup.push_back (Baxter);
      theGroup.push_back (Caroline);
      theGroup.push_back (David);
      theGroup.push_back (Erin);
      theGroup.push_back (Frank);
      theGroup.push_back (Gemma);
      theGroup.push_back (Hassan);
  
      for (int n = 0, iterations = (theGroup.size() - 2); n &lt;= iterations; n++)
          Voting (theGroup);
  
      cout &lt;&lt; "ANNA VOTED FOR...";
      for (int n = 0; n &lt;= 5; n++)
      {
          cout &lt;&lt; "Round " &lt;&lt; (n + 1) &lt;&lt; ": " &lt;&lt; Anna.GetVote(n) &lt;&lt; '\n';
      }
  
      cin.ignore();
      return 0;
  }
  </code></pre>