title: how to create array of an abstract class in c++
body: <p>I am trying to create a program that takes food order and prints it out. I have my base class <code>Food</code> which has a pure virtual function in it. Class Food has 2 subclass <code>Pizza</code> and <code>Dessert</code>. I am trying to make an array of <code>Food</code> in my <code>main</code> so when a customer orders <code>Pizza</code> or <code>Dessert</code>, it will be stored in the array of <code>Food</code>. But every time I try, I get an error. How should I put the two items together then if I want to use a loop to go over each item the customer ordered?
  This is my code:</p>
  
  <pre><code>int main()
  {
    Dessert d("brownie");
    Pizza p("BBQ delux");
    Food array[2] = {d,p};
  }
  </code></pre>
  
  <p>This is my error message. (NOTE: <code>get_set_price()</code> and <code>print_food()</code> are my pure virtual functions which is defined in base class and implemented in the 2 subclasses)</p>
  
  <pre><code>main.cpp:37:14: error: invalid abstract type ‘Food’ for ‘array’
    Food array[2] = {d,p};
  
  In file included from main.cpp:4:0:
  Food.h:5:7: note:   because the following virtual functions are pure within ‘Food’:
   class Food
         ^
  
  Food.h:20:15: note:     virtual void Food::get_set_price()
    virtual void get_set_price()=0;
                 ^
  
  Food.h:27:15: note:     virtual void Food::print_food()
    virtual void print_food()=0; 
                 ^
  
  main.cpp:37:22: error: cannot allocate an object of abstract type ‘Food’
    Food array[2] = {f,o};
                    ^
  </code></pre>