title: Wrong value on first element in std::vector
body: <p>I am learning c++ i am fearly new, i found a bug in my code and could reproduce with a example, in this code i am generating some price objects and adding it to a std::vector, why the value of <strong>close</strong> inside the object Price for the first element is aparently a random value in memory ? is this a reference issue ?</p>
  <pre><code>#include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  
  class Price{
  public:
      double entry;
      double close;  
      Price(double initial){
          entry = initial;
      }
  };
  
  int main(){
      std::vector&lt;Price&gt; prices;
      bool open = false;
      int index = 1;
      std::cout &lt;&lt; &quot;#######  before  ########&quot; &lt;&lt; std::endl;
      while (index &lt; 10){
          if (open){
              Price current = prices[prices.size() - 1];
              current.close = -current.entry;
              open = false;
              std::cout &lt;&lt; &quot;open: &quot; &lt;&lt; current.entry &lt;&lt; &quot; | close: &quot; &lt;&lt; current.close&lt;&lt;std::endl;
          }
          else{
              Price new_price(index);
              prices.push_back(new_price);
              open = true; 
          }
          ++index;
      }
      std::cout &lt;&lt; std::endl &lt;&lt; &quot;#######  after  ########&quot; &lt;&lt; std::endl;
      for(const auto price: prices){
          std::cout &lt;&lt; &quot;open: &quot; &lt;&lt; price.entry &lt;&lt; &quot; | close: &quot; &lt;&lt; price.close &lt;&lt; std::endl;
      }
  }
  </code></pre>
  <p>The output generated by the above code is:</p>
  <pre><code>#######  before  ########
  open: 1 | close: -1
  open: 3 | close: -3
  open: 5 | close: -5
  open: 7 | close: -7
  
  #######  after  ########
  open: 1 | close: 4.6799e-310
  open: 3 | close: -1
  open: 5 | close: -3
  open: 7 | close: -5
  open: 9 | close: -7
  </code></pre>
  <p>Also if i change <code>Price current = prices[prices.size() - 1];</code>to <code>Price&amp; current = prices[prices.size() - 1];</code> the value of <strong>close</strong> for the last element is now corrupted and the first is fine. I am lost, can someone explain this behavior to me?</p>