title: Why can't I print contents of vector of objects using a ranged for loop?
body: <p>I'm a beginner and I solved an exercise involving 10 pie eaters with number of pies eaten set by user input. </p>
  
  <ol>
  <li>1st task: Display Contestant number and pies eaten - Solved;</li>
  <li>2nd task: Find winners with most pies eaten and list all - Solved;</li>
  <li>3rd task: Find losers with least pies eaten and list all - Solved;</li>
  <li>Final task: Sort Contestants and list them in order of most pies to
  least pies eaten - Partially Solved.</li>
  </ol>
  
  <p>I did everything, no errors or warnings (even stepping over/ into in debugger showed that the vector was sorted correctly), but right when I try to print out the sorted vector, the console screen just won't display anything more (not even the standard message that program execution is finished).</p>
  
  <p>I made a Contestant class with constructor Contestant with two arguments, and declared a vector of objects. Here's the code in main, class header and class solution: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include "Contestant.h"
  using namespace std;
  
  int main()
  {
      cout &lt;&lt; "Type the number of pies eaten by each of the 10 contestants:" &lt;&lt; endl;
      cout &lt;&lt; "#1 #2 #3 #4 #5 #6 #7 #8 #9 #10" &lt;&lt; endl;
  
      vector&lt;Contestant&gt; pie_eaters;
      vector&lt;Contestant*&gt; winners; 
      vector&lt;Contestant*&gt; losers; 
  
  
      for (int i=0; i&lt;10; i++)
      {
         int pies_eaten;
         cin &gt;&gt; pies_eaten;
         pie_eaters.emplace_back(i+1, pies_eaten);
         cout &lt;&lt; "Contestant number " &lt;&lt; i+1 &lt;&lt; " ate " &lt;&lt; pie_eaters[i].GetPancakes() &lt;&lt; endl;
      }
      cout &lt;&lt; endl;
  
  
      FindWinners(pie_eaters, winners);
      ListWinners(winners);
  
      FindLosers(pie_eaters, losers);
      ListLosers(losers);
  
  
      cout &lt;&lt; endl;
  
      SortPieEaters(pie_eaters);
  
      ListSortedPieEaters(pie_eaters);
  
  
  }
  </code></pre>
  
  <p>Class header (edited, just for the sorting and printing out, which are outside the class):</p>
  
  <pre><code>#pragma once
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  class Contestant
  {
  private: 
      int pancakes_eaten;
      int number;
  
  public:
      Contestant(int number, int pancakes);
  
      ~Contestant();
      int GetPancakes() const { return pancakes_eaten; }
      int GetNumber() const { return number; }
  
  };
  
  
  void SortPieEaters(std::vector&lt;Contestant&gt;&amp; pie_eaters);
  
  void ListSortedPieEaters(std::vector&lt;Contestant&gt; const&amp; pie_eaters);
  </code></pre>
  
  <p>and Class solution (just the sorting and printing out parts, which are outside the class):</p>
  
  <pre><code>#include "Contestant.h"
  
  using namespace std;
  
  Contestant::Contestant(int number, int pancakes) : pancakes_eaten(pancakes), number(number)
  {
  }
  
  Contestant::~Contestant() {};
  
  
  void SortPieEaters(vector&lt;Contestant&gt;&amp; pie_eaters)
  {
      while(bool swapped=true)
          {
          swapped = false;
             for (int i = 0; i &lt; static_cast&lt;int&gt;(pie_eaters.size()-1); i++)
             {
                  if (pie_eaters[i].GetPancakes() &lt; pie_eaters[i + 1].GetPancakes())
                  {
                      swap(pie_eaters[i], pie_eaters[i + 1]);
                      swapped = true;
                  }
  
             }
          }
  }
  
  void ListSortedPieEaters(vector&lt;Contestant&gt; const&amp; pie_eaters)
  {
      cout &lt;&lt; "From most pies eaten, to fewest pies eaten, the results are as follows:" &lt;&lt; endl;
      for (auto const&amp; c : pie_eaters)
      {
          cout &lt;&lt; "Contestant #" &lt;&lt; c.GetNumber() &lt;&lt; ": ate " &lt;&lt; c.GetPancakes() &lt;&lt; " pies" &lt;&lt;endl;
  
      }
  }
  </code></pre>
  
  <p>And lastly, here's and example output:
  <a href="https://i.stack.imgur.com/JA69v.jpg" rel="nofollow noreferrer">Output</a></p>
  
  <p>Everything works fine, but it won't print out the vector or warn there are any issues with it. Tried, everything like passing by constant or non-constant reference, tried writing the body of the function directly in main(avoiding the function), but nothing.
  And accessing the vector and printing out content was the same as in the case of the winner and losers vectors (even though they are vectors of pointers to the object elements of the pie eaters vector)</p>
  
  <p>What am I doing wrong?</p>