title: Class Composition Constructor d Must Explicitly initialize the reference member
body: <p>I am really stuck with the problem here.
  So basically I have a <code>Stock</code> class and a <code>BuyOrder</code> class.The <code>BuyOrder</code> class takes the <code>Stock</code> class as a member so it knows which stock to buy. When the stock is created, it takes in a company name and initializes with random prices. Then I can create a buy order takes in  <code>bidPrice</code>,<code>bidQuantity</code>,<code>Stock</code> arguments.</p>
  
  <p>In the <code>main</code> I want to create an array of <code>BuyOrder</code> to store the orders. Then every time the user created an order, the order can be stored.</p>
  
  <p>My first approach is to declare <code>BuyOrder buyList[100]</code>. This way every time the user created an order, I can use the set functions to set each <code>buyList[i]</code> and then increment i. However, when I declare <code>BuyOrder buyList[100]</code>in <code>main</code>. It says <code>No matching constructor for initialization of 'BuyStock buyList[100]'</code> I went back to <code>BuyOrder.cpp</code> try to add a default constructor <code>BuyOrder::BuyOrder(){}</code> then it shows the error:<code>Constructor for 'BuyOder'must explicitly initialize the reference member 'buyStock'</code>. </p>
  
  <p>I don't know how to proceed from here. Very much appreciated.</p>
  
  <p>Below is part of BuyOrder.cpp since it way too long and the rest part are just function definitions. </p>
  
  <pre><code>BuyOrder::BuyOrder{double price, int quantity, Stock &amp;s)
  :buyPrice{price},
   buyQuantity{quantity},
   buyStock{s}{}
  
  void BuyOrder::setBuyStock(Stock stock){
      buyStock = stock;
  }
  
  void BuyOrder::setBuyOrderPrice(double price) {
      buyPrice = price;
  }
  
  void BuyOrder::setBuyOrderQuantity(int quantity) {
      buyQuantity = quantity;
  </code></pre>
  
  <p>Below is BuyOrder.h</p>
  
  <pre><code>#ifndef BUYORDER_H
  #define BUYORDER_H
  #include &lt;ctime&gt;
  #include&lt;iostream&gt;
  #include "Stock.h"
  
  
  class BuyOrder {
      friend void getCurrentTime();
  
  public:
      BuyOrder(double , int , Stock &amp; );
  
      void setBuyStock(Stock);
      void setBuyOrderPrice(double price);
      void setBuyOrderQuantity(int quantity);
  
      double getBuyOrderPrice();
      int getBuyOrderQuantity();
  
      void placeBuyOrder();
      void checkExcute();
  
      void modifyBuyOrder();
      void cancelBuyOrder();
  
      double getHighestBidPrice();
      int getHighestBidPriceQuantity();
  
      double getLowestBidPrice();
      int getLowestBidPriceQuantity();
  
  private:
      double buyPrice;
      int buyQuantity;
      bool excute = false;
      Stock &amp;buyStock;
      time_t t;
  
  };
  #endif
  </code></pre>
  
  <p>This is the Stock.h</p>
  
  <pre><code>#ifndef STOCK_H
  #define STOCK_H
  #include &lt;vector&gt;
  #include &lt;string&gt;
  using namespace std;
  
  class Stock {
  
      friend void getCurrentTime();
  
  
  public:
      Stock();
      Stock(string nameOfCompany);
  
      int getBidTerms();
      int getAskTerms();
      void printStockInfo();
      void initialize();
      void sortBid();
      void sortAsk();
  
      string nameOfCompany;
      string currentTime;
  
      vector&lt;double&gt; askPrice;
      vector&lt;int&gt; askQuantity;
  
      vector&lt;double&gt; bidPrice;
      vector&lt;int&gt; bidQuantity;
  
      int bidTerm;
      int askTerm;
  
  };
  #endif
  </code></pre>
  
  <p>and this is Stock.cpp excluding the long function definitions</p>
  
  <pre><code>#include "Stock.h"
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;time.h&gt;
  #include &lt;iomanip&gt;
  #include &lt;ctime&gt;
  #include &lt;random&gt;
  #pragma warning(disable : 4996)
  using namespace std;
  
  
  void getCurrentTime() {
  
      time_t rawTime;
      struct tm * timeinfo;
  
      time(&amp;rawTime);
      timeinfo = localtime(&amp;rawTime);
      cout &lt;&lt; asctime(timeinfo);
  }
  
  Stock::Stock(){}
  
  Stock::Stock(string companyName) :nameOfCompany{ companyName } {
      initialize();
      sortBid();
      sortAsk();
  }    
  </code></pre>