title: Using pointer to base class as array parameter
body: <p>I have 2 classes:</p>
  
  <pre><code>class Base
  {
  public:
       virtual int Foo(int n);
           virtual void Goo() = 0;
       virtual ~Base() ;
  };
  
  
  class Derived : public Base
  {
  public:
      int Add4Bytes;
  
          void Goo();
      int  Foo(int n);    
  };
  
  int Test(Base* b)
  {
      for (int i=0;i&lt;5;++i)
      {
          b-&gt;Foo(i);
          ++b;
      }
      return 0;
  }
  
  void Test2(Base arr[])
  {
      for (int i=0;i&lt;5;++i)
      {
          arr[i].Foo(i);
      }
  }
  
  void main
  {
  
        Base* b = new Derived[5];
        Test(b);
  }
  </code></pre>
  
  <p>So, when i'm calling Test, after the second loop there a memory viloation exception.</p>
  
  <p>I have 2 questions:</p>
  
  <ol>
  <li>What's the difference between the function argument in Test and Test2 ? (Test2 doesn't compile after i turned Base into pure abstract class).  </li>
  </ol>
  
  <p>and the more important question</p>
  
  <ol start="2">
  <li>How can i prevent that exception, and how can i pass an array of derived class to a function that suppose to get a base class array.  (i can't tell in compile time which derived class i'm gonna pass the function)</li>
  </ol>
  
  <p>p.s - please don't tell me to read Meyers book,  that's the exact reason why i'm asking this question. :)</p>
  
  <p>Thanks</p>