title: inhertiance: How can I make an array of different classes, with the same function, that do different things in C++?
body: <p>So in my code I would like to make an array of classes. This is because I want to change the order with which they do things. However, I need the classes in this array to have a function that is the same name but will do different things, depending on the type of class that is called. </p>
  
  <p>For example, let's say I make an array of Cars. Every car has a function called drive() that determines the speed with which it drives.  I make an array of Cars "CarArray[]" In it, I put two types of classes, Hondas and Fords. Both Hondas and toyotas inherit from the base class of Cars. They both have a function called drive(). If I call CarrArray[].drive() and I get a honda, it should out put a different value than if the space were occupied by a Ford.</p>
  
  <p>So, for example, let's say I make a Honda drive at 10 mph and a Ford drive at 30 mph. </p>
  
  <p>My Array looks like this:</p>
  
  <p>CarArray [0] // Honda</p>
  
  <p>CarArray [1] // Ford</p>
  
  <p>CarArray [2] //Honda</p>
  
  <p>If I call CarArray[0].drive() I should get 10 mph </p>
  
  <p>But if I call CarArray[1].drive I should get 30 mph. </p>
  
  <p>Since it is an array. I can manipulate the classes and switch them around so I get different values. </p>
  
  <p>In my program I want to do more than just print out values but I hope you get the idea.</p>
  
  <p>Here is my test code. </p>
  
  <pre><code>        #include &lt;iostream&gt;
  
  using namespace std;
  
  
  class BaseClass{
  public:
  
   virtual void OutPut();
  
  protected:
  
          int BaseData;
  };
  void BaseClass::OutPut(){
      cout&lt;&lt; "BaseClass printed something"&lt;&lt;endl;
  }
  
  class BaseA: public BaseClass{
  public:
  
   virtual void OutPut();
  
  protected:
  
          int BaseData;
  };
  
  void BaseA::OutPut(){
      cout&lt;&lt; "BaseA printed something"&lt;&lt;endl;
  }
  
   class BaseB: public BaseClass{
  public:
  
   virtual void OutPut();
  
  protected:
  
          int BaseData;
  };
  
  void BaseB::OutPut(){
      cout&lt;&lt; "BaseB printed something"&lt;&lt;endl;
  }
  int main()
  {
  
  
  BaseA Class1;
  BaseB Class2;
  
  BaseClass BaseArray[2];
  
  BaseArray[0] = Class1;
  BaseArray[1] = Class2;
  
  BaseArray[0].OutPut();
  BaseArray[1].OutPut();
  
  
  return 0;
  }
  </code></pre>